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

注册于 3年前

回答
417
文章
0
关注者
15

请提供完整代码....不然谁能知道你是怎么排出来这个效果的...

image.png

Learning from egreg's elegant solution by box manipulation:

\documentclass{article}
\usepackage{amsmath,amsfonts}
\newcommand{\lastcfrac}[2]{%
      \raisebox{\dimexpr1ex-\height}{%
        $\displaystyle
          \raisebox{.5\height}{$\ddots$}+\cfrac{#1}{#2}
        $%
      }%
    }
\begin{document}
    \[
        q_0 + \cfrac{1}{q_1 + \cfrac{1}{q_2 + \ddots +\cfrac{1}{q_n}}} 
    \]

    \[
        q_0 + \cfrac{1}{q_1 + \cfrac{1}{q_2+\lastcfrac{1}{q_n}}} 
    \]
\end{document}

image.png

嗯..我个人觉得比原图的省略号更美观...

Claim:其实这更多的是一个数学问题...

个人探索的另一个更优雅和直观的方式是基于「一些神必的数学」

image.png

而更碰巧的是,tikz提供了「coordinate transformation matrix」这样的feature

所以可以得到如下个人觉得比较简单的实现:

\documentclass[tikz,border=5pt]{standalone}
\begin{document}
\def\radius{1}
\def\height{1.05}%to tune the eccentricity
\def\leftheight{2}
\def\rightheight{4}
\def\midheight{\fpeval{(\leftheight+\rightheight)/2}}
\def\hh{\fpeval{abs(\leftheight-\rightheight)/2}}
\begin{tikzpicture}[line join=round]
    \draw[dashed] (\radius,0) arc (0:180:{\radius} and {1/3});
    \draw (-\radius,0) arc (180:360:{\radius} and {1/3});
    \draw (-\radius,0) -- (-\radius,\leftheight) coordinate (A);
    \draw (\radius,0) -- (\radius,\rightheight) coordinate (B);
    \def\phii{\fpeval{acos(\hh/\height)}}
    \def\xa{0}
    \def\ya{\fpeval{-\height*sin(\phii)}}
    \def\xb{\radius}
    \def\yb{\fpeval{\height*cos(\phii)}}
    \draw[cm={\xa,\ya,\xb,\yb,(0,\midheight)}] circle [radius=1cm];
    \filldraw[red] (A) circle[radius=.5pt] node[left,text=black] {$A$}
                   (B) circle[radius=.5pt] node[right,text=black] {$B$};
    \node[align=left,rectangle] at (\radius+4,\rightheight/2) {%
        $\phi$ \texttt{=\phii}\\
        $(x_1,y_1)$ \texttt{=(\xa,\ya)}\\
        $(x_2,y_2)$ \texttt{=(\xb,\yb)}
    };
\end{tikzpicture}
\end{document}

image.png

欣赏一下局部细节

image.png

Edit

忽然想到:

要欣赏一下局部细节

tikz提供了spy这样的工具,尝尝鲜嘻嘻

\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{spy}
\begin{document}
\def\radius{1}
\def\height{1.05}%to tune the eccentricity
\def\leftheight{2}
\def\rightheight{4}
\def\midheight{\fpeval{(\leftheight+\rightheight)/2}}
\def\hh{\fpeval{abs(\leftheight-\rightheight)/2}}
\begin{tikzpicture}[
    line join=round,
    line cap=round,
    spy using outlines={%
        circle,size=2cm,
        magnification=10,
        connect spies
    }%
]
    \draw[dashed] (\radius,0) arc (0:180:{\radius} and {1/3});
    \draw (-\radius,0) arc (180:360:{\radius} and {1/3});
    \draw (-\radius,0) -- (-\radius,\leftheight) coordinate (A);
    \draw (\radius,0) -- (\radius,\rightheight) coordinate (B);
    \def\phii{\fpeval{acos(\hh/\height)}}
    \def\xa{0}
    \def\ya{\fpeval{-\height*sin(\phii)}}
    \def\xb{\radius}
    \def\yb{\fpeval{\height*cos(\phii)}}
    \draw[cm={\xa,\ya,\xb,\yb,(0,\midheight)}] circle [radius=1cm];
    \node[align=left,rectangle] at (\radius+4,1) {%
        $\phi$ \texttt{=\phii}\\
        $(x_1,y_1)$ \texttt{=(\xa,\ya)}\\
        $(x_2,y_2)$ \texttt{=(\xb,\yb)}
    };
    \spy[red] on (A) in node [left] at (-1,4);
    \spy[blue] on (B) in node [right] at (2.5,3);
\end{tikzpicture}
\end{document}

image.png

这是一个不太好的解答,但提供了一个倾斜椭圆绘制的轮子...

要想更方便地仅通过椭圆的「长轴端点」和「离心率」来控制「倾斜」的椭圆,我正好在这里有一个类似的封装\mydrawellipse

稍微调整了一下:

\documentclass[tikz,border=2pt]{standalone}
\usepackage{tkz-euclide}
\NewDocumentCommand{\mydrawellipse}{O{}O{}mmm}{%
  % #3=pointA; #4=pointB; #5=ratio of y on x
  \tkzCalcLength(#3,#4)%
  \tkzGetLength{tmpdistance}%
  \tkzFindSlopeAngle(#3,#4) %
  \tkzGetAngle{tmpangle}%
  \begin{scope}[rotate=\tmpangle]
  \draw[densely dashed,#1] (#4) arc [start angle=0,delta angle=180,
  x radius=\fpeval{\tmpdistance/2} cm,y radius=\fpeval
  {\tmpdistance * (#5) / 2}cm] (#3);
  \draw[#2] (#3) arc[start angle=180,delta angle=180,x
  radius=\fpeval{\tmpdistance/2} cm,y radius=\fpeval{\tmpdistance
  * (#5) / 2}cm] (#4);
  \end{scope}
}

\begin{document}
\begin{tikzpicture}[line join=round]
  \def\radius{1}
  \def\height{4}
  \def\leftheight{1.5}
  \def\rightheight{3}
  \tkzDefPoint(-\radius,0){A}
  \tkzDefPoint(\radius,0){B}
  \tkzDefPoint(-\radius,\leftheight){C}
  \tkzDefPoint(\radius,\rightheight){D}
  \mydrawellipse{A}{B}{.2}
  \mydrawellipse[solid]{C}{D}{.18}
  \def\myshifta{.004}
  \def\myshiftb{.003}
  \tkzDefPoint(-\radius-\myshifta,0){A'}
  \tkzDefPoint(\radius+\myshiftb,0){B'}
  \tkzDefPoint(-\radius-\myshifta,\leftheight){C'}
  \tkzDefPoint(\radius+\myshiftb+.003,\rightheight-.01){D'}
  \tkzDrawSegments[line width=.4pt](A',C' B',D')
\end{tikzpicture}
\end{document}

但是,由于数学上的原因,「直接以母线上的点作为长轴顶点」的话,椭圆与圆柱的母线必不是相切的。OP提到的「这里的x radiusy radius怎么调都调不好...」正是由于此,客观来看,上面代码中的

\def\myshifta{.004}
\def\myshiftb{.003}
\tkzDefPoint(-\radius-\myshifta,0){A'}
\tkzDefPoint(\radius+\myshiftb,0){B'}
\tkzDefPoint(-\radius-\myshifta,\leftheight){C'}
\tkzDefPoint(\radius+\myshiftb+.003,\rightheight-.01){D'}
\tkzDrawSegments[line width=.4pt](A',C' B',D')

纯属气急败坏的无奈之举,局部的微调精细效果也并不够完美。

image.png

image.png

image.png

注意,本站不是「PDF分享」站

提问就要focus在真正体现你问题的关键点上,给可以体现你问题的示例代码

我帮你在原问题里补充了「最小工作示例」,希望你下次提问能自己给出

image.png


也不太难,看下原码即可:

% elegantbook.cls Line 1165
%% Example with counter
\newcounter{exam}[chapter]
\setcounter{exam}{0}
\renewcommand{\theexam}{\thechapter.\arabic{exam}}
\newenvironment{example}[1][]{
  \refstepcounter{exam}
  \par\noindent\textbf{\color{main}{\examplename} \theexam #1 }\rmfamily}{
  \par\ignorespacesafterend}

想办法把上面的设置覆盖掉即可...

\documentclass[lang=cn,11pt,twoside,openany]{elegantbook}
\geometry{paperheight=10cm}
\counterwithin{exam}{section}
\renewcommand{\theexam}{\thesection.\arabic{exam}}
\begin{document}%

\chapter{test}
\section{sec}

\begin{example}
test test test test
\end{example}

\begin{example}
    test test test test
\end{example}

\section{sec}

\begin{example}
    test test test test
\end{example}

\chapter{test}
\section{sec}

\begin{example}
    test test test test
    \end{example}
    
    \begin{example}
        test test test test
    \end{example}
    
    \section{sec}
    
    \begin{example}
        test test test test
    \end{example}
\end{document}  

image.png

注意:这样只修改了example环境,对于同样属于「示例类环境」的problemexercise环境的修改,也是类似的...留做习题...

原来的MWE已经确认为nicematrix的bug,可关注相关issues.

基于nicematrix的文档18.5中例子的一个workaround,使用了较旧的\Submatrix\Overbrace命令:

image.png

不过并不够优雅,例如下面的m_in_j居然要以两种并不对偶的方式来输入:

\documentclass{article}
\usepackage[OT1]{fontenc}
\usepackage{eulervm}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
% https://tex.stackexchange.com/a/112212/322482
\makeatletter
\DeclareRobustCommand{\rvdots}{%
  \vbox{
    \baselineskip4\p@\lineskiplimit\z@
    \kern-\p@
    \hbox{.}\hbox{.}\hbox{.}
  }}
\makeatother
\usepackage{nicematrix}
\setlength{\extrarowheight}{1mm}
\begin{document}
\[ 
% a little syntax inconsisitency in this example
\begin{pNiceArray}{cccc}[margin,last-col,cell-space-limits=5pt]
    A_{11}  & A_{12}  & \cdots & A_{1s}  & \enspace m_1 \\
    A_{21}  & A_{22}  & \cdots & A_{2s}  & \enspace m_2 \\
    \rvdots & \rvdots & {}     & \rvdots & \quad \rvdots \\
    A_{r1}  & A_{r2}  & \cdots & A_{rs}  & \enspace m_r \\
    \CodeAfter
    \OverBrace[yshift=1mm]{1-1}{1-1}{n_1} 
    \OverBrace[yshift=1mm]{1-2}{1-2}{n_2} 
    \OverBrace[yshift=1mm]{1-3}{1-3}{\cdots} 
    \OverBrace[yshift=1mm]{1-4}{1-4}{n_s}
    \SubMatrix{.}{1-4}{1-4}{\rbrace}[xshift=4mm]
    \SubMatrix{.}{2-4}{2-4}{\rbrace}[xshift=4mm]
    \SubMatrix{.}{3-4}{3-4}{\rbrace}[xshift=4mm]
    \SubMatrix{.}{4-4}{4-4}{\rbrace}[xshift=4mm]
\end{pNiceArray}
\]
\end{document}

image.png

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

贴个「最佳实践」吧...(我还是觉得不够优雅,这显然是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

发布
问题