Sagittarius Rover
Sagittarius Rover
这家伙很懒,什么也没写!

注册于 3年前

回答
456
文章
0
关注者
15

不知道你要干什么,不要贴一大堆代码,看着很累...

贴个「最佳实践」吧...(我还是觉得不够优雅,这显然是pdfpages宏包_应该_提供的内置功能...理论上翻issues更合理)

Learning From this link:

\documentclass[a4paper]{article}
\usepackage{l3graphics}
\usepackage{pdfpages}
\begin{document}
\ExplSyntaxOn
\graphics_get_pagecount:nN {test.pdf} \l_tmpa_tl
\int_step_inline:nn {\l_tmpa_tl} {
     \includepdf[pages={#1},fitpaper]{test.pdf} % PDF.file with differernt papersize
}
\ExplSyntaxOff
\end{document}

image.png

由于没有提供「huatu1.pdf」, MWE不规范...另外当遇到报错,作为提问者理应提供「报错信息」

image.png

很遗憾,直接复制粘贴在「别人的电脑上」无法编译复现你遇到的错误...

上面的代码在我本地无法编译...建议提供当前项目的压缩包并对这段代码想实现的效果做详细介绍。

大致有以下几个问题:

  • pgffor没用上...调用它做什么呢...
  • expl3已经进入latex2e内核,因此会自动调用,无需自行显式调用
  • \int_step_i_nline:nn这个函数不存在,这里 似乎 应该用\int_step_inline:nn,请仔细阅读texdoc interface3而非问AI...
  • P.S. 是pdfpages不好用吗...

祝好!


Edit

既然你的提问标题是「一段expl3代码无法编译」

这里不会关心你的实际需求,只提供为何出错?实际上和latex3并无关系。

你的问题可以更简化的MWE为:

\documentclass{article}
\usepackage{pdfpages}
\newcommand{\getpdfpages}[1]{%
    \pdfximage{#1}%
    \the\pdflastximagepages%
}
\begin{document}
The page is:\getpdfpages{example-image.pdf}
\end{document}

当使用pdflatex编译时,可以正常得到PDF为example-image的页数为1:
image.png

而当使用xelatex编译时,将得到:

! Undefined control sequence.
\getpdfpages #1->\pdfximage
                            {#1}\the \pdflastximagepages
l.11 The page is \getpdfpages{example-image.pdf}

?

这是因为\pdfximagepdfTeX提供的宏,无法使用xelatex编译。

另外,代码中:

  • \usepackage[UTF8]{ctex}并没有发挥作用
  • 使用现代引擎编译文档时,默认编码默认即为UTF8,所以这里也是没有必要显式写出UTF8的...

Update 20250715:

有一种可能是用户在安装时没有选择「full-scheme」

image.png

如果选择了medium而不是full安装方案,有可能会影响一些字体方面的,很讨厌
我自己非常建议新人就 scheme-full

——by OsbertWang

如果遇到了上述问题,且texlive要是已经安装完了
用户可以尝试使用下面的命令「full-scheme」重新安装并刷新字体缓存:

tlmgr --reinstall install scheme-full

请提供一个完整的,可让人直接编译能复现你问题最短代码。

你提供的代码内容 惜码如金 ,连]都没闭合...

image.png

为了追求更高质量的位置、长度自定义,如「方正」、「规整」等,同时受我自己的这个回答启发,我也用tikzmatrix子库自己实现了...

下面保留了matrix of math nodes的边界:

\documentclass{article}
\usepackage[OT1]{fontenc}
\usepackage{eulervm}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calligraphy,matrix}
% https://tex.stackexchange.com/a/112212/322482
\makeatletter
\DeclareRobustCommand{\rvdots}{%
  \vbox{
    \baselineskip4\p@\lineskiplimit\z@
    \kern-\p@
    \hbox{.}\hbox{.}\hbox{.}
  }}
\makeatother
\newcommand*\myHbrace[3][0pt]{%
    \draw[mybrace] (foo-#2.north west) -- node[above=3pt] {#3} (foo-#2.north east);
}%
\newcommand*\myVbrace[3][8pt]{%
    \draw[mybrace=#1] (foo-#2.north east) -- node[right=8pt] {#3} (foo-#2.south east);
}%
\begin{document}

\begin{tikzpicture}[
        every left delimiter/.style={xshift=.5em},
        every right delimiter/.style={xshift=-.5em},
        % https://tex.stackexchange.com/a/525165/322482
        mybrace/.default=3pt,
        mybrace/.style = {
                    thick,pen colour=black,
                    decorate,
                    decoration={
                        calligraphic brace, amplitude=2pt,
                        pre =moveto, pre  length=1pt,
                        post=moveto, post length=1pt,
                        raise=#1},
                    },
    ]
        \matrix (foo) [
            matrix of math nodes,
            % default linewidth = .4pt
            column sep=-.4pt,row sep=-.4pt,
            anchor=center,
            nodes = {
                draw=magenta,dashed,
                inner sep=1pt,outer sep=0pt,
                minimum size=.75cm,anchor=center,
            },
            left delimiter=(,right delimiter=),
        ]
        {
            A_{11} & A_{12}   & \cdots & A_{1s}  \\
            A_{21} & A_{22}   & \cdots & A_{2s}  \\
            \rvdots & \rvdots &        & \rvdots \\
            A_{r1} & A_{r2}   & \cdots & A_{rs}  \\
        };
        \myHbrace{1-1}{$n_1$}
        \myHbrace{1-2}{$n_2$}
        \node[above=3pt] at (foo-1-3.north) {$\cdots$};
        \myHbrace{1-4}{$n_s$}
        \myVbrace{1-4}{$m_1$}
        \myVbrace{2-4}{$m_2$}
        \node[right=12pt] at (foo-3-4.east) {$\rvdots$};
        \myVbrace{4-4}{$m_r$}
\end{tikzpicture}

\end{document}

image.png

应该注重版本差异与相应的更新日志。

感觉这上面的图像某个数学益智小游戏...

  • tabularray方案(耐心即可)
tabularray 能不能做到精确控制单元格边框?

可以,耐下心看看对应部分的文档即可,真的不长,而且你目标明确...

\documentclass{article}
\usepackage{libertinus}
\usepackage{tabularray}
\setlength\lTblrDefaultHruleWidthDim{2pt}% 
\setlength\lTblrDefaultVruleWidthDim{2pt}%
\begin{document}
\begin{tblr}{
    colspec = *{4}{Q[c,.75cm]},
    stretch=0,
    rows = {ht=1cm,font=\bfseries\Large},
    hline{1} = {1-2}{},
    hline{2} = {1-2,4}{},
    hline{3-4},
    vline{1} = {1,3}{},
    vline{2-3},
    vline{4-5} = {2-3}{},
    }
    A & B &   &   \\
      & C &   & D \\
    E & F & G & H \\
\end{tblr}
\end{document}

不过我觉得控制严格「正方形」可能不总是太轻松....

image.png

Edited(权宜之计)

这样是不是也勉强可行呢...语法更加简单一些...

\documentclass{article}
\usepackage{libertinus}
\usepackage{tabularray}
\usepackage{xcolor}
\begin{document}
\begin{tblr}{
    colspec = *{4}{Q[c,.75cm]},
    stretch=0,
    rows = {ht=1cm,font=\bfseries\Large},
    cell{1}{1-2} = {bg=gray!20},
    cell{2}{2,4} = {bg=gray!20},
    row{3} = {bg=gray!20},
    }
    A & B &   &   \\
      & C &   & D \\
    E & F & G & H \\
\end{tblr}
\end{document}

image.png

但我总觉得还有更便捷和更自动化的方法

TBC.

  • tikz方案,也许可以定义坐标系,如果内容「A,B,...,H」 的大小不变的话,封装一个「在给定坐标绘制对应node」的命令也许可行(?)

不擅长tikz...我不打算用了

另外,总是应该先看看文档,最好不要过于依赖ds。

感谢 @u73286 Eureka老师提供的思路:

-?(?:\d+\.\d*|\.\d+|\d+)
tblr 里面有一个 cmd 键, 可以把这个判断写在 cmd里面

PS1.该问题不需要多个嵌套表格,所以mwe代码理论上不应该用三合一的表格
PS2.在tabularray中上面例子的\usepackage{siunitx}是无法生效的,请看文档第五章
PS3.在article文档类选项中的UTF8是不用显式写出的,已经是默认值


\documentclass{article}
\usepackage{libertinus} % for better looking of number
\usepackage{xcolor}
\usepackage{tabularray}
\ExplSyntaxOn
\newcommand*{\mycolorednum}[2][red]{%
    \regex_if_match:nnTF{\A -?(?:\d+\.\d*|\.\d+|\d+) \Z} { #2 }
    {
        \textcolor{ #1 }{ #2 }
    }
    {
        #2
    }
}
\ExplSyntaxOff
\begin{document}
\begin{tblr}{
    colspec = *{4}{c},
    hlines,vlines,
    cells = {cmd = \mycolorednum[magenta]},
    }
    1     & test   & 2 & -1.33\\
    3     & 2test  & text & 21.2 \\
    test-3  & test   & 4 & 2.33\\ 
    test1   & 5     & 2test   & 8 \\
    -6      & test  & 100     & test2 \\
    -1test  & -80    & 66.6     & 4test \\ 
    0.09   & -888    & -0.08  & 231 \\
    test1   & -5    & 2test   & -8 \\
    6      & test  & 100     & test2 \\
    -.1tt  & 80    & 666     & 4test \\ 
    0.09  & -.567   & .08    & 2test \\
\end{tblr}
\end{document}

image.png

In the x-post, the best practice of this requirement is documented in the manual.

TL;DR

dash expand off is all what I need.

Makes the off part of a dash pattern expandable such that it can stretch. This only works when there is a single on and a single off field and requires the decorations library. Right now this option has to be specified on the path where it is supposed to take effect after the dash pattern option because the dash pattern has to be known at the point where it is applied.

image.png

Code & Result Comparsion:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{ext.shapes.superellipse}
\begin{document}
\begin{tikzpicture} [
      densely dashed,
    % dash expand off,
      every node/.append style={
        draw=blue,
        fill=yellow,
        thick,
        inner sep=2pt,
        font=\LARGE,
      },
    ]
  \node [circle] {1};
  \node [ellipse] at (1,0) {2};
  \node [ext_superellipse,font=\tiny] at (2.25,0) {233333};
\end{tikzpicture}

\begin{tikzpicture} [
    densely dashed,
    dash expand off,
    every node/.append style={
      draw=violet,
      fill=magenta,
      thick,
      inner sep=2pt,
      font=\LARGE,
    },
  ]
\node [circle] {1};
\node [ellipse] at (1,0) {2};
\node [ext_superellipse,font=\tiny] at (2.25,0) {233333};
\end{tikzpicture}

\end{document}

image.png

This can handle all the case by stretch the "off" part at the end, regardless of the node's content or the shape. IMHO, it's the best practice of this case.

提问时尽量给出最小工作示例,摒弃所有与问题无关的内容

这140行代码中90%与你问题无关

好好看看这两天我给你简化了多少代码,这些简化根本不用动脑,只是自己不愿动手。

\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots} % 核心绘图库
\pgfplotsset{compat=1.18} % 版本兼容性设置
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = middle,
    xmin = 0, xmax = 8,
    ymin = 0, ymax = 6,
    ]
    \addplot[                
        domain = 1:7.2831,      
        samples = 300,       
        smooth,              
        line width = 0.5pt,  
        black                 
    ] {sin(deg(x-1))+2.5};    
    \coordinate (A) at (axis cs:1,2.5);
    \coordinate (B) at (axis cs:7.2831,2.5);
    \coordinate (C) at (axis cs:2.5708,3.5);
    \coordinate (D) at (axis cs:5.7123,1.5);
    \pgfplotsinvokeforeach {A,B,C}{%
        \node[above] at (#1) {$#1$};
    }
    \node[below] at (D) {$D$};
\end{axis}

\end{tikzpicture}
\end{document}

image.png

读文档第九章第四节 drawing scheme

image.png

改用finish而不是overlay app即可。

另外,既然文字需要被「装饰」遮盖住,那这个文字被排出来的作用是什么呢? 建议提供一下具体的应用场景。

\documentclass{article}
\usepackage[UTF8]{ctex}
\usepackage[most]{tcolorbox}
\usetikzlibrary{patterns}
\usepackage{zhlipsum}
\begin{document}

\tcbset{
  frogbox/.style={
    enhanced,
    colback=green!10,
    colframe=green!65!black,
    enlarge top by=5.5mm,
    overlay={
      \foreach \x in {2cm, 3.5cm} {
        \begin{scope}[shift={([xshift=\x]frame.north west)}]
          \path[draw=green!65!black, fill=green!10, line width=1mm] (0,0) arc (0:180:5mm);
          \path[fill=black] (-0.2,0) arc (0:180:1mm);
        \end{scope}
      }
    }
  },
  ribbon/.style={
    finish={
      \path[
        fill=blue!75!white,
        draw=blue,
        double=white!85!blue,
        preaction={fill=blue!75!white},
        line width=0.1mm,
        double distance=0.2mm,
        pattern=fivepointed stars,
        pattern color=white!75!blue
      ]
      ([xshift=-0.2mm, yshift=-2.02cm]frame.north east)
      -- ++(-2,2)
      -- ++(-0.5,0)
      -- ++(2.5,-2.5)
      -- cycle;
    }
  }
}

\begin{tcolorbox}[frogbox, ribbon, title=My title]
\zhlipsum[1]
\end{tcolorbox}

\end{document}

image.png

这是一个非常有意义的问题

Learning From this link

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
    foo /.tip = {Straight Barb[]Bar[width=10pt,sep=+0pt +-.5]},
    ]
    \draw[foo-foo] (-.5,0) -- (-.5,2) node[midway,left] {$2$};
    \draw[foo-foo] (-.5,2) -- (-.5,2+1) node[midway,left] {$1$};
    \draw[foo-foo] (0,0) -- (0,2) node[midway,left] {$2$};
    \draw[foo-foo] (.5,2) -- (.5,2+1) node[midway,left] {$1$};
    \fill[red] (0,2) circle (0.3pt);
    \fill[red] (.5,2) circle (0.3pt);
\end{tikzpicture}
\end{document}

image.png

但...作为提问的代码还可以更加简短,也应该更加简短。

你关注的只是两个自定义箭头的相连问题,为什么要贴一整个正方形的绘制代码出来?这个图与你问题的核心点有关系吗?

这同样将大大增加别人的阅读负担。

请总是给出可以体现你问题的最短代码。


Edit

在上面的链接中提到,Qrrbrbirlbel已经将符合这一特征的箭头加入TikZ-Extensions包中,查阅手册我们知道:

这种箭头特征被称为「untipped」

image.png

换言之,下面的代码可以更优雅地实现相同的效果:

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{ext.arrows}
\begin{document}
\begin{tikzpicture}[
    foo /.tip = {Straight Barb[]ext_Untipped Bar[width=10pt]},
    ]
    \draw[foo-foo] (-.5,0) -- (-.5,2) node[midway,left] {$2$};
    \draw[foo-foo] (-.5,2) -- (-.5,2+1) node[midway,left] {$1$};
    \draw[foo-foo] (0,0) -- (0,2) node[midway,left] {$2$};
    \draw[foo-foo] (.5,2) -- (.5,2+1) node[midway,left] {$1$};
    \fill[red] (0,2) circle (0.3pt);
    \fill[red] (.5,2) circle (0.3pt);
\end{tikzpicture}
\end{document}

image.png

0.请有简化你问题的意识,不要让别人看一大堆与你问题无关的代码。

明明下面的十几行就可以完全反映你的问题,为什么要上传七八十行的代码(?) Tell Me Why?! Why?!

这给别人增加了很大的负担

\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = middle,
    xmin = -0.05, xmax = 1.1,
    ymin = -0.05, ymax = 1.4,
    axis line style = {-{Triangle[length=8pt, width=3pt]}},
    ytick distance = 0.2,
    ]
    \addplot[domain=0:1.4, thick, blue, samples=100] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}

1.比较简陋的做法

坐标轴刻度线与箭头距离太近,增大xmaxymax时坐标轴并没有延长相应的单位长度

指定ymax=1.35不可以吗? 不是很清楚你的具体需求?

\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = middle,
    xmin = -0.05, xmax = 1.1,
    ymin = -0.05, ymax = 1.35,
    axis line style = {-{Triangle[length=8pt, width=3pt]}},
    ytick distance = 0.2,
    ]
    \addplot[domain=0:1.4, thick, blue, samples=100] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}

image.png

2.使用tikzarrow提供的shorten >=功能调整「箭头末端」的长度:

文档

image.png

\documentclass[tikz,border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    axis lines = middle,
    xmin = -0.05, xmax = 1.1,
    ymin = -0.05, ymax = 1.4,
    axis line style = {-{Triangle[length=8pt, width=3pt]},shorten >=-.8cm},
    ytick distance = 0.2,
    ]
    \addplot[domain=0:1.4, thick, blue, samples=100] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}

这将在保持使用ymax=1.4的同时得到:

image.png

请务必简化你的代码,不要一发发一大堆,其中大部分内容与你的问题无关。还有,若代码较短,请用「markdown代码块」而不是「上传附件」给出。

发布
问题