远方不远
远方不远
Hello, LuaLaTeX!

注册于 2年前

回答
29
文章
0
关注者
0

在下面这则article文档类的示例文档中,你将得到一个section条目从3开始编号的目录:

% mwe-article.tex
\documentclass{article}
\addtocounter{section}{2}
\begin{document}
\tableofcontents
\section{section one}   text one.
\section*{section two}  text two.
\section{section three} text three.
\end{document}

在下面这则beamer文档类的示例文档中,你将得到一个section条目从1开始编号的目录:

% mwe-beamer.tex
\documentclass{beamer}
\setbeamertemplate{section in toc}[sections numbered]
\addtocounter{section}{2}
\begin{document}
\frame{ \frametitle{\contentsname} \tableofcontents }
\section{section one}
\frame{ \frametitle{section one}   text one. }
\section*{section two}
\frame{ \frametitle{section two}   text two. }
\section{section three}
\frame{ \frametitle{section three} text three. }
\end{document}

尽管两份示例文档都在导言区使用\addtocounter{section}{2},但是预期效果只在artile文档类中实现,而在beamer文档类中没有实现。出现这种情况的原因是,虽然这两个文档类都定义了名字相同的\section命令及其星号版本,但这两个文档类对\section命令及其星号版本的定义方式不同。更具体地说,是两个文档类各自的\section命令及其星号版本对写入目录的要求不同。

beamer.cls中,有以下代码:

%% line 79 
\newcount\beamer@tocsectionnumber

其含义是,新分配一个名为\beamer@tocsectionnumber且缺省值为0count型寄存器count型寄存器能够储存一个数值的浮点数部分和整数部分。要对该寄存器赋值,可以使用<count型寄存器>=<数值>。要打印它的当前数值,可以使用\the<count型寄存器>。当浮点数部分不存在时,只会打印整数部分。在TeX中,可以使用\advance <count型寄存器> by <数值>,来使<count型寄存器>内部储存的数值加或减<数值>。通过这种方式,这类寄存器可以被用于计数,所以可以也可以叫它“计数器”。

现在,要找到beamer目录的section条目编号的具体症结,需要查看.toc文件:

% mwe-article.toc
\contentsline {section}{\numberline {3}section one}{1}{}%
\contentsline {section}{\numberline {4}section three}{1}{}%
% mwe-beamer.toc
\beamer@sectionintoc {3}{section one}{2}{0}{1}
\beamer@sectionintoc {5}{section three}{4}{0}{2}

mwe-article.toc中,第一则目录条目的构成是(见source2e.pdf\contentsline条目):

\contentsline 
    {<该标题的标题类型:section>}
    {\numberline {<该标题在正文中的计数器section的当前值:3>}<该标题的正文内容:section one>}
    {<该标题所在页面的计数器page的当前值:1>}
    {<该标题的超链接锚点:>}`%

mwe-beamer.toc中,第一则目录条目的构成是(见beamerbasesection.sty的代码行\addtocontents{toc}{\protect\beamer@sectionintoc{...}}中省略号处的内容):

\beamer@sectionintoc 
    {<该标题在正文中的计数器section的当前值:3>}
    {<该标题的正文内容:section one>}
    {<该标题所在的页面的计数器page的当前值:2>}
    {<该标题所在的部分的计数器part的当前值:0>}
    {<该标题在目录中的计数器\beamer@tocsectionnumber的当前值:1>}

从中可见,命令\section及其星号版本,在写入目录时,其在beamer文档类中的行为与在标准文档类中的行为不同。

mwe-article.toc中,写入目录的是该标题在正文中的计数器section的值,而在mwe-beamer.toc中,写入目录的是该标题在目录中的计数器\beamer@tocsectionnumber的值。也就是说,在beamer中,由\section命令及其星号版本给出的标题,其在正文中和目录中的编号采用的是不同的编号方法。

那么二者是否存在数值上的依赖关系?我的答案是:我没找到,所以我认为目前二者不存在数值依赖关系。

那么二者具有怎么样的关系?答案是:在beamer中,

  1. 默认情况下,计数器\beamer@tocsectionnumber只给由\section给出的标题从1开始编号——换言之,它是一个“纯粹”且全局连续的计数器。所以在mwe-beamer.toc中,我们看到的两个条目的第5个参数,是连续的从1开始的编号12——因为\addtocounter{section}{2}没有对计数器\beamer@tocsectionnumber产生影响,所以服从默认情况,从1开始编号;而“连续”是显然的,因为计数器\beamer@tocsectionnumber只给由\section给出的标题编号。
  2. 而计数器section既会给由\section给出的标题编号,也会给由\section*给出的标题编号——换言之,它是一个“不纯粹”且全局连续的计数器。由于\addtocounter{section}{2}对计数器section产生影响,所以从3开始编号。所以在mwe-beamer.toc中,我们看到的两个条目的第1个参数,是连续的从3开始的编号35——遇到\section*{section two}时,计数器section为其编号为4,但beamer默认不让由\section*给出的标题进入目录,所以\section*{section two}没有被写入.toc文件,不过本质上3,4,5是连续的。如果使\section*{section two}进入目录,我们将看到:
% (如果允许星号标题进入目录的)mwe-beamer.toc
\beamer@sectionintoc {3}{section one}{2}{0}{1}
\beamer@sectionintoc {4}{section two}{3}{0}{}%%这是我的预测和想象,不一定准确
\beamer@sectionintoc {5}{section three}{4}{0}{2}

最后,解决办法是:

% way 1:
\makeatletter
\beamer@tocsectionnumber=2\relax
\makeatother

% way 2:
\makeatletter
\advance\beamer@tocsectionnumber by 2\relax
\makeatother

...\texmf-dist\tex\latex\beamer\beamerbasesection.sty文件的第176行附近,似乎提供了beamer的section的相关定义。有如下表述:

\beamer@tocsectionnumber=0\relax

虽然不知道其含义,但是,只要将其放在导言区,并重新赋值,即可将第二份演示文稿的目录中的section的起始编号设置为问题所需。即,在导言区添加:

\makeatletter
\beamer@tocsectionnumber=2\relax
\makeatother

即可得到:
image.png

命令\circledtext{<arg>}中的<arg>可以是“普通”的未经处理的阿拉伯数字,也可以是经过处理的阿拉伯数字。
这样的话,就可以使用由\graphicx宏包提供的\scalebox{<h-scale>}[<v-scale>]{<arg>}命令作为命令\circledtext{<arg>}的参数——可能\scalebox命令是健壮的,所以无需保护而不报错。
总之,效果大概是这样:
image.png
image.png

\documentclass[tikz,border=2pt]{standalone}
\usepackage{ctex}
\usepackage{graphicx}
\usepackage{circledtext}
\begin{document}
\tikz{
    \foreach \x in {0,...,9} {
        \node 
            at (\x,0)
            [scale=2.75] 
            {\circledtext{\x}};
    }
    \foreach \x in {10,...,19} {
        \node 
            at (\x-10,1)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
    \foreach \x in {20,...,29} {
        \node 
            at (\x-20,2)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
    \foreach \x in {30,...,39} {
        \node 
            at (\x-30,3)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
    \foreach \x in {40,...,49} {
        \node 
            at (\x-40,4)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
    \foreach \x in {50,...,59} {
        \node 
            at (\x-50,5)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
    \foreach \x in {60,...,69} {
        \node 
            at (\x-60,6)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
    \foreach \x in {70,...,79} {
        \node 
            at (\x-70,7)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
    \foreach \x in {80,...,89} {
        \node 
            at (\x-80,8)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
    \foreach \x in {90,...,99} {
        \node 
            at (\x-90,9)
            [scale=2.75] 
            {\circledtext{\scalebox{1.25}[2]{\x}}};
    }
}
\tikz{
        \foreach \x in {100,...,109} {
        \node 
            at (\x-100,10)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {110,...,119} {
        \node 
            at (\x-110,11)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {120,...,129} {
        \node 
            at (\x-120,12)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {130,...,139} {
        \node 
            at (\x-130,13)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {140,...,149} {
        \node 
            at (\x-140,14)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {150,...,159} {
        \node 
            at (\x-150,15)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {160,...,169} {
        \node 
            at (\x-160,16)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {170,...,179} {
        \node 
            at (\x-170,17)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {180,...,189} {
        \node 
            at (\x-180,18)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
    \foreach \x in {190,...,199} {
        \node 
            at (\x-190,19)
            [scale=2.75] 
            {\circledtext{\scalebox{1}[2]{\x}}};
    }
}
\end{document}

最懒惰的方法,当二维图画。
自己改一下

\documentclass[border=2pt, tikz]{standalone} 
\usetikzlibrary{calc}
\begin{document} 
\begin{tikzpicture}[scale=5]
    \coordinate (B) at (0,0);
    \coordinate (A) at ($(B)+(45:1)$);
    \coordinate (D) at ($(B)+(0:1.25)$);
    \coordinate (C) at ($(B)+(-20:1)$);
    \draw [thick] (B)--(A)--(D)--(C)--cycle (A)--(C);
    \coordinate (B') at ($(B)!.5!(A)$);
    \coordinate (C') at ($(A)!.45!(C)$);
    \coordinate (D') at ($(A)!.5!(D)$);
    \coordinate (F)  at ($(D)!.5!(C)$);
    \coordinate (E)  at ($(C)!.5!(B)$);
    \coordinate (G)  at ($(B)!.55!(D)$);
    \coordinate (M)  at ($(B')!.5!(F)$);
    \draw [dashed] (B)--(D) (B')--(F) (D')--(E);
    \foreach \x in {C',G,M} \fill (\x) circle (.25pt);
    \node at (A) [above] {$A$};
    \node at (B') [above left,inner sep=0pt] {$B'$};
    \foreach \x in {B,C'} \node at (\x) [left] {$\x$};
    \node at (E) [below left] {$E$};
    \node at (M) [left=.1cm] {$M$};
    \node at (D') [above right] {$D'$};
    \node at (D) [right] {$D$};
    \node at (F) [below right] {$F$};
    \foreach \x in {C,G} \node at (\x) [below] {$\x$};
\end{tikzpicture}
\end{document} 

凑个热闹
MWE中凡与此问题无关联的内容都应该酌情删改,否则可能影响潜在答题者的解答质量。
实际上,你的导言区只需要这几句代码:

% !TEX program = pdflatex
\documentclass[openany]{book}
\usepackage[many]{tcolorbox}
\usepackage{hyperref}

应该等你确实需要了,再往导言区加东西。例如,添加你的额外需求实现\Doubleref

% !TEX program = pdflatex
\documentclass[openany]{book}
\usepackage[many]{tcolorbox}
\usepackage{hyperref}
\NewDocumentCommand{\Doubleref}{m}{{\color{red}Definition \ref{#1} (\nameref{#1})}}

总之,做MWE时秉持越少越好原则,才能更方便地排查错误。
然后我也浅答一个,完全用tcolorbox实现的效果:
image.png
image.png
image.png
image.png
而要实现这个效果,只需如下定制即可:

\newtcbtheorem
    [number within=chapter]
    {definition}
    {Definition}
    {
        fonttitle=\bfseries\color{black},
        opacityback=0,
        left=.25em,
        right=.25em,
        top=.45ex,
        bottom=.45ex,
        before skip=2pt plus 2pt minus 1pt,
        after skip =6pt plus 2pt minus 4pt,
        arc=0pt,
        enhanced,
        breakable,
        boxrule=0pt,
        frame hidden,
        borderline south={1pt}{0mm}{black},
        borderline west ={1pt}{0mm}{black},
        borderline east ={1pt}{0mm}{black},
        attach boxed title to top left={
            yshift=-3mm,
            yshifttext=-1mm,
            xshift=3em 
        },
        overlay unbroken and first={
            \draw [line width=1pt] (title.west) -- ++(-3em+.5pt,0pt) -- ++(down:\baselineskip);
            \draw [line width=1pt] (title.east) -- ++( 3em,0pt);
        },
        overlay middle and last={},
        boxed title style={
            frame style   ={fill=none},
            interior style={fill=none},
            left=.25em,
            right=.25em,
            top=.45ex,
            bottom=.45ex
        }
    }
    {def}

其中参数的含义是:

\newtcbtheorem
    [<初始化选项>]            %上面用到了计数器关联,也可以在此处理cleveref兼容问题
    {<新环境的name>}          %用于\begin{}...\end{}的环境名
    {<用于展示的name>}        %用于排版结果中展示的环境名
    {<定制tcb的选项>}         %主要是操纵外观
    {<标签的前缀>}            %人为将标签分为前缀、分隔符(默认使用英文冒号)和主体

然后在正文区使用

\begin{<新环境的name>}{<定理的标题文本>}{<标签的主体>}
    ...
\end{<新环境的name>}

例如

\begin{definition}{GouGu}{gougu}
    ...
\end{definition}

即可创建一个基于定制tcolorbox的新定理。
然后在正文区其他地方使用

\Doubleref{<标签的前缀>:<标签的主体>}

例如

\Doubleref{def:gougu}

即可交叉引用。
如需兼容cleveref宏包,需注意导言区的代码顺序,且需要在\newtcbtheorem的可选参数[<初始化选项>]里增加,Crefname={Definition}{Definitions}。然后即可采用由cleveref宏包提供的交叉引用类型。


原题没有提出断页需求,因此未进行测试,代码已修改。原来使用的frame code app在不断页的条件下的确可以正常工作,但是当分页发生时,主盒子会被保存到一个寄存器中,所以原先的主盒子会消失,这将导致原先的盒子的追加代码失效。在tcb手册中对此问题有专门叙述,解决方案之一是分别定制盒子的前中后部分以及不可断页共四种类型的皮肤。完整代码在此。

要实现“不用加载任何其他”这个需求对我来说有点难,除非你更喜欢用雾月老师的方法在底层用vrule画正字。

在unicode编码表的算筹字符区(Counting Rod Numerals),就有你需要的五个字符,然而不是所有的字库文件都会收录它们。要想直接使用它们,你必须使用已经收录了它们的字体,所以你就必须加载“这种字体”才能在文档中写正字。例如开源的霞鹜文楷字体,就收录了它们。字体千千万,所以如果采用unicode字符的方法,需要你自己去考察你所希望的字体对这些字符的收录情况。

image.png


(第一次更新被删除了)


(第二次更新)又测试了下,这样就可以了。核心包是etoolbox,主要用途是进行判断。因为全部使用ASCII字符,所以不怕编辑器显示不出来:

\documentclass[UTF8]{ctexart}
\usepackage[hscale=.8,papersize={10cm,5cm},showframe]{geometry}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\usepackage{etoolbox}
\newfontfamily{\XWWKen}{LXGW WenKai}
\NewDocumentCommand{\zheng}{ O{} }{%
    \ifstrequal{#1}{1}{\symbol{"1D372}}{%
        \ifstrequal{#1}{2}{\symbol{"1D373}}{%
            \ifstrequal{#1}{3}{\symbol{"1D374}}{%
                \ifstrequal{#1}{4}{\symbol{"1D375}}{%
                    \ifstrequal{#1}{5}{\symbol{"1D376}}{%
                        \ifstrempty{#1}{\symbol{"6B63}}{%
                            \GenericError{}%  
                                {(zheng command) Invalid argument '#1'}%
                                {You should use '1' or '2' or '3' or '4' or '5' or leave empty.}%
                        }%
                    }%
                }%
            }%
        }%
    }%
}

\begin{document}

\huge\XWWKen

\zheng \quad \zheng[]

\zheng[1] \quad \zheng[2] \quad \zheng[3] \quad \zheng[4] \quad \zheng[5] 

%\zheng[6] %输入阿拉伯数字"1""2""3""4""5"之外的任何内容,都将报错。

\end{document}

image.png


第三次更新)稍微改造和拓展了下这个命令,第一,通常的命令\zheng[#1]只能绘制一个正字,但是有5种形态,以及可以使可选参数为空为0或不带方括号(这三种形态将什么也不做,并且取消掉原来输出U+6b63字符的效果,这是因为直接用输入法打出那个字更方便),而新的\zhengs[#1]可以指定正字的笔画数量,最大1024(当然是可以直接改成更大的笔画上限),还需要更多的话请用循环语句,第二,添加了一个粘连,这个值使用的是xeCJKCJKglue默认值,这样可以支持自动换行,像雾月老师那样可以把正字装在高高窄窄的盒子里,第三,就命令本身而言,使用了数值比较函数而不是字符串比较函数,减轻了命令的参数判断的严格程度,第四,核心包新增使用了expl3,但其实是内核的东西,算不上额外的包,这是我第一次接触L3,写的不好。
image.png
image.png

\documentclass[UTF8]{ctexart}
\usepackage[hscale=.8,papersize={18cm,12cm},showframe]{geometry}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\newfontfamily{\XWWKen}{LXGW WenKai}
\usepackage{etoolbox}
\usepackage{xcolor}
\ExplSyntaxOn
\NewDocumentCommand{\zheng}{ O{} }
{
    \ifstrempty{#1}
    {}
    {
        \ifnumequal{#1}{0}
        {}
        {
            \ifnumequal{#1}{1}
            {\symbol{"1D372}}
            {
                \ifnumequal{#1}{2}
                {\symbol{"1D373}}
                {
                    \ifnumequal{#1}{3}
                    {\symbol{"1D374}}
                    {
                        \ifnumequal{#1}{4}
                        {\symbol{"1D375}}
                        {
                            \ifnumequal{#1}{5}
                            {\symbol{"1D376}}
                            {
                                \message{zheng~command~Warning:~The~parameter~'#1'~was~too~large.
                                ~I~replaced~it~with~the~remainder~of~the~parameter~divided~by~5}%信息会显示在.log文件中 
                                \int_set:Nn \l_tmpa_int { \int_div_truncate:nn { #1 } { 5 } }%相除后向下取整,得到商 \l_tmpa_int
                                \int_set:Nn \l_tmpb_int { #1 - \l_tmpa_int * 5 }%参数除以5得到的余数 \l_tmpb_int
                                \ifnumequal{\l_tmpb_int}{0}%判断余数为几,然后输出对应的正字
                                {\zheng[5]}
                                {
                                    \ifnumequal{\l_tmpb_int}{1}
                                    {\zheng[1]}
                                    {
                                        \ifnumequal{\l_tmpb_int}{2}
                                        {\zheng[2]}
                                        {
                                            \ifnumequal{\l_tmpb_int}{3}
                                            {\zheng[3]}
                                            {
                                                \ifnumequal{\l_tmpb_int}{4}
                                                {\zheng[4]}
                                                {}
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
\NewDocumentCommand{\zhengs}{ O{} }
{
    \ifstrempty{#1}
    {}
    {
        \ifnumcomp{#1}{<}{1}
        {}
        {
            \ifnumcomp{#1}{<}{1025}
            {
                \int_set:Nn \l_tmpa_int { \int_div_truncate:nn { #1 } { 5 } }
                %相除后向下取整,得到应该重复使用\zheng[5]的次数 \l_tmpa_int
                \int_step_inline:nn { \l_tmpa_int } { \zheng[5] \hskip 0pt plus 0.08\baselineskip }
                %重复使用\zheng[5],总共 \l_tmpa_int 次,并插入一个粘连,使它可以自动换行
                \int_set:Nn \l_tmpb_int { #1 - \l_tmpa_int * 5 }%参数除以5得到的余数 \l_tmpb_int
                \ifnumequal{\l_tmpb_int}{0}%判断余数为几,然后输出对应的正字
                {\zheng[0]}
                {
                    \ifnumequal{\l_tmpb_int}{1}
                    {\zheng[1]}
                    {
                        \ifnumequal{\l_tmpb_int}{2}
                        {\zheng[2]}
                        {
                            \ifnumequal{\l_tmpb_int}{3}
                            {\zheng[3]}
                            {
                                \ifnumequal{\l_tmpb_int}{4}
                                {\zheng[4]}
                                {}
                            }
                        }
                    }
                }
            }
            {\GenericError{}{(zhengs~command)~Argument~'#1'~is~too~large.
             ~The~maximum~parameter~value~only~accepts~1024.}{}{}}
        }
    }
}
\ExplSyntaxOff 

\begin{document}

\newcounter{myline}
\newcommand{\myline}{\color{black}\stepcounter{myline}\themyline.\,}

\huge\XWWKen

\addtocounter{myline}{-4}\myline\color{red}\zheng\color{cyan}\zhengs

\myline\color{red}\zheng[]\color{cyan}\zhengs[]

\myline\color{red}\zheng[0]\color{cyan}\zhengs[0]

\addtocounter{myline}{1}\myline\color{red}\zheng[1]\color{cyan}\zhengs[1]

\myline\color{red}\zheng[2]\color{cyan}\zhengs[2]

\myline\color{red}\zheng[3]\color{cyan}\zhengs[3]

\myline\color{red}\zheng[4]\color{cyan}\zhengs[4]

\myline\color{red}\zheng[5]\color{cyan}\zhengs[5]

\myline\color{red}\zheng[6]\color{cyan}\zhengs[6]

\myline\color{red}\zheng[7]\color{cyan}\zhengs[7]

\myline\color{red}\zheng[8]\color{cyan}\zhengs[8]

\myline\color{red}\zheng[9]\color{cyan}\zhengs[9]

\myline\color{red}\zheng[10]\color{cyan}\zhengs[10]

\myline\color{red}\zheng[11]\color{cyan}\zhengs[11]

\myline\color{red}\zheng[12]\color{cyan}\zhengs[12]

\addtocounter{myline}{1011}\myline\color{red}\zheng[1024]\color{cyan}\zhengs[1024]

\myline\color{red}\zheng[1025]%\color{cyan}\zhengs[1025]

\end{document}

因为你输入的是英文的括号,所以tex就给你排版英文括号
image.png
而作为英文字符,使用的是times new roman字体
image.png

哪儿错了?
关于编译TeX源文档这种入门级问题,请阅读lshort.
9bc32b9ce078c7c2c4b5dcef0f3e356f.png

创建mwe.mp文件,输入下方代码后保存:

verbatimtex                                          
%&latex 
\documentclass{article}
\usepackage{CJK}       
\begin{CJK}{UTF8}{gbsn}
\begin{document}      
etex            

beginfig(1);
drawarrow origin--(0,100);
drawarrow origin--(100,0);
drawdot origin withpen pencircle scaled 2pt;
label.bot(btex 原点 etex, origin);
label.lft(btex $y$ etex, (0,100));
label.lrt(btex $x$ etex, (100,0));
endfig;

verbatimtex
\end{CJK}
\end{document}
etex

end

然后在win10+TL2025的电脑上,命令行输入mptopdf mwe.mp进行编译,得到mwe-1.pdf

image.png

其中使用的汉字是gbsn,但TL上貌似不能任意更换字体。

image.png

以下内容是我胡邹的:

tabularray从这一段看来:似乎是将总表宽与某一刚性长度进行比较,然后决定是否给出该警告:

\cs_new_protected:Npn \__tblr_compute_extendable_column_width:
{
\__tblr_collect_extendable_column_width:
\dim_compare:nNnTF { \l__column_target_dim } < { 0pt }
{
\msg_warning:nnx { tabularray } { table-width-too-small }
{ \dim_abs:n { \l__column_target_dim } }
}
{
\prop_if_empty:NF \l__column_coefficient_prop
{ \__tblr_adjust_extendable_column_width: }
}
}

standalone的页面尺寸,似乎不是一开始就决定了的:

\newbox\sa@box
\pagestyle{empty}
\hoffset=-72.27pt
\voffset=-72.27pt
\topmargin=0pt
\headheight=0pt
\headsep=0pt
\marginparsep=0pt
\marginparwidth=0pt
\footskip=0pt
\marginparpush=0pt
\oddsidemargin=0pt
\evensidemargin=0pt
\topskip=0pt
\textheight=\maxdimen
\def\sa@boxit{%
    \setbox\sa@box\hbox\bgroup\color@setgroup\sa@varwidth
}%
\def\endsa@boxit{%
    \sa@endvarwidth\color@endgroup\egroup
}%

所以standalone不断地在计算页面尺寸,直到tabularray已经将表格拼装完成后,standalone计算页面尺寸的工作还未结束,以致tabularray只好将当前standalone计算出的最终页面尺寸进行比较,所以tabularray等不及了就抛出了该警告。

  • 翻了下wrapfig的宏包手册,发现要使用这个包实现第一行排满之后,再排第二行,且末行左对齐这个效果,经过多次测试——不是特别容易实现:这主要是你的需求仍有表述不清之处导致的。
  • 在这个宏包条件下,图片尺寸是影响第一行行末提前折行的关键因素,但是第一行行末排满再折行,与图表的尺寸和位置,二者总是很难协调。
  • 众所周知,TeX在图文绕排方面存在所谓固有限制,所以最好的方法是避免图文绕排,或者尽量避免采取较为复杂的图文绕排效果而是只追求较为简单的图文混排效果。

下面抛砖引玉,介绍一些图文绕排的常见方案。

第一个方法LaTeX提供了minipage环境,比较通用,只要提前规划好内容,就可以用这种粗略的方法实现;

%%无需加载额外宏包
%%方法1%%
    \begin{frame}{1. \texttt{minipage}方案}
        
        如图,闭合回路中有多个电源,若电动势 \(\mathcal{E}_1\) 大于 电动势 \(\mathcal{E}_2\),则电流方向如图。
        
        \vskip2ex%
        \begin{minipage}{.7\linewidth}
            规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。
        \end{minipage}%
        \begin{minipage}{.3\linewidth}
            \centering
            \includegraphics[height=3\baselineskip]{example-image}
        \end{minipage}%
        \vskip2ex
        
        \begin{itemize}
            \item 对于 \(\mathcal{E}_1\):电流方向与电动势方向一致,电荷经过时静电力做负功,电势升高 \(\mathcal{E}_1\)
            \item 对于 \(\mathcal{E}_2\):电流方向与电动势方向相反,电荷经过时静电力做正功,电势降低 \(\mathcal{E}_2\),此时相当于电阻。
        \end{itemize}
        
    \end{frame}

第二个方法beamer文档类提供了columns环境,它是一个可以比较便捷的用于左文右图的排版方案;

%%无需加载额外宏包
%%方法2%%
    \begin{frame}{2. \texttt{columns}方案}
        
        如图,闭合回路中有多个电源,若电动势 \(\mathcal{E}_1\) 大于 电动势 \(\mathcal{E}_2\),则电流方向如图。
        
        \vskip2ex%
        \begin{columns}[onlytextwidth]
        \column[c]{.7\linewidth}
            规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。
        \column[c]{.3\linewidth}
            \centering
            \includegraphics[height=3\baselineskip]{example-image}
        \end{columns}%
        \vskip2ex
        
        \begin{itemize}
            \item 对于 \(\mathcal{E}_1\):电流方向与电动势方向一致,电荷经过时静电力做负功,电势升高 \(\mathcal{E}_1\)
            \item 对于 \(\mathcal{E}_2\):电流方向与电动势方向相反,电荷经过时静电力做正功,电势降低 \(\mathcal{E}_2\),此时相当于电阻。
        \end{itemize}
        
    \end{frame}

第三个方法tcolorbox宏包提供了同名环境,其 并排下部 功能是比较现代的左右混排方案,缺点是不能换页,不过在beamer中帧换页本身大多数时候无效,因此屏蔽了这个缺点。由于该宏包的高度可定制化,故推荐优先级最高;

%%\usepackage{tcolorbox}
%%方法3%%
    \begin{frame}{3. \texttt{tcolorbox}方案}
        如图,闭合回路中有多个电源,若电动势 \(\mathcal{E}_1\) 大于 电动势 \(\mathcal{E}_2\),则电流方向如图。
        \begin{tcolorbox}[
            enhanced,
            frame hidden,
            opacityback=0,
            sidebyside,
            righthand ratio=.3,
            lower separated=false,
            sidebyside gap=0mm,
            left=0cm,
            right=0cm,
            boxsep=0pt,
            boxrule=0pt,
        ]
            规定电动势的方向:
            正极通过外电路指向负极的方向;
            负极通过内电路指向正极的方向。
            \tcblower
            \centering
            \includegraphics[height=3\baselineskip]{example-image}
        \end{tcolorbox}
        
        \begin{itemize}
            \item 对于 \(\mathcal{E}_1\):电流方向与电动势方向一致,电荷经过时静电力做负功,电势升高 \(\mathcal{E}_1\)
            \item 对于 \(\mathcal{E}_2\):电流方向与电动势方向相反,电荷经过时静电力做正功,电势降低 \(\mathcal{E}_2\),此时相当于电阻。
        \end{itemize}
        
    \end{frame}

上述三种方法,对于左右型、上下型排版需求,都是可行的策略。下面介绍一些应对特殊型绕排需求的方法。

第四个方法,李清老师的wrapstuff宏包提供了图文绕排的另一种实现,它的优点是可以自由地对需要绕排的图表进行水平或垂直方向上的偏移

  • wrapstuff尝试整合和扩展picinparfloatfltwrapfigcutwinwrapfig2等同类宏包的功能,且兼容captionfloatfloatrow等宏包,并试图兼容显示(display)数学公式和各种 LaTeX 列表环境,可以让他们正确绕排。如果需要将图表绕排在列表环境(问题描述中的第三段)附近,也可以试试这个包。
  • 需要注意的是,wrapstuff的实现依赖LaTeX 2021-06-01开始提供的段落钩子,并依赖LaTeX3 2022-04-10之后的版本。
%%\usepackage{wrapstuff}
%%方法4%%
    \begin{frame}{4.1 \texttt{wrapstuff}方案}
        
        如图,闭合回路中有多个电源,若电动势 \(\mathcal{E}_1\) 大于 电动势 \(\mathcal{E}_2\),则电流方向如图。
        
        \vskip3ex%
        \begin{wrapstuff}[r,top=0,width=.2\linewidth,vsep=0pt,voffset=-2mm]
            \includegraphics[height=\dimeval{3\baselineskip}]{example-image}
        \end{wrapstuff}%
        规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通。
        \wrapstuffclear
        
        \vskip3ex%
        \begin{itemize}
            \item 对于 \(\mathcal{E}_1\):电流方向与电动势方向一致,电荷经过时静电力做负功,电势升高 \(\mathcal{E}_1\)
            \item 对于 \(\mathcal{E}_2\):电流方向与电动势方向相反,电荷经过时静电力做正功,电势降低 \(\mathcal{E}_2\),此时相当于电阻。
        \end{itemize}
        
    \end{frame}
    \begin{frame}{4.2 \texttt{wrapstuff}方案}
        
        如图,闭合回路中有多个电源,若电动势 \(\mathcal{E}_1\) 大于 电动势 \(\mathcal{E}_2\),则电流方向如图。
        
        \vskip3ex%
        \begin{wrapstuff}[r,top=0,width=.2\linewidth,vsep=0pt,voffset=-2mm]
            \includegraphics[height=\dimeval{3\baselineskip}]{example-image}
        \end{wrapstuff}%
        规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通。
        \wrapstuffclear
        
        \vskip3ex%
        \begin{wrapstuff}[r,top=0,width=.2\linewidth,vsep=0pt]
            \includegraphics[height=\dimeval{3\baselineskip}]{example-image}
        \end{wrapstuff}%
        规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向。
        
    \end{frame}

第五个方法wrapfig通常作为picinpar宏包的互补解决方案,wrapfig宏包的优点是可以不必指定把多少文字包含进绕排的范围,且可以让图表超出版心而不报错。

  • 然而wrapfigpicinpar一样,在本页剩下的空间中必须足够放下被绕排的图表,也就是说起码这个段落的“边界盒子”的上下界要能够包含该图表。你的提问中,图表到底跟哪一段成绕排关系,并未说清,因此我只能按照我自己的想法来操作。所以我就假设你只是想在第二段绕排,不过显然的是该段文字数量略少,因此极大可能造成难看的分页。
  • 在我的测试中,发现段落的高度至少要超过图表的总高度以及图表上下的额外垂直间距之和两行以上,这种在一个段落的右上角排版图片的绕排方案才能取得比较好的视觉效果。
  • 所以使用此包,需要改进的观点是:在wrapfigure环境后面,必须紧跟着字数足够多的纯文本段落,否则排版通常会非常难看。
%%\usepackage{wrapfig}
%%方法5%%
    \begin{frame}{5.1 \texttt{wrapfig}方案}
        
        如图,闭合回路中有多个电源,若电动势 \(\mathcal{E}_1\) 大于 电动势 \(\mathcal{E}_2\),则电流方向如图。
        
        \vskip3ex%
        \begin{wrapfigure}[5]{r}[0pt]{.2\textwidth}
            \centering
            \includegraphics[height=3\baselineskip]{example-image}
        \end{wrapfigure}%
        规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通。
        \vskip3ex%
        
        \begin{itemize}
            \item 对于 \(\mathcal{E}_1\):电流方向与电动势方向一致,电荷经过时静电力做负功,电势升高 \(\mathcal{E}_1\)
            \item 对于 \(\mathcal{E}_2\):电流方向与电动势方向相反,电荷经过时静电力做正功,电势降低 \(\mathcal{E}_2\),此时相当于电阻。
        \end{itemize}
        
    \end{frame}
        \begin{frame}{5.2 \texttt{wrapfig}方案}
        
        如图,闭合回路中有多个电源,若电动势 \(\mathcal{E}_1\) 大于 电动势 \(\mathcal{E}_2\),则电流方向如图。
        
        \vskip3ex%
        \begin{wrapfigure}[5]{r}[0pt]{.2\textwidth}
            \centering
            \includegraphics[height=3\baselineskip]{example-image}
        \end{wrapfigure}%
        规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通。
        \vskip3ex%
        \begin{wrapfigure}[5]{r}[0pt]{.2\textwidth}
            \centering
            \includegraphics[height=3\baselineskip]{example-image}
        \end{wrapfigure}%
        规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方向。规定电动势的方向:正极通过外电路指向负极的方向;负极通过内电路指向正极的方方方方向向向。
        
    \end{frame}

最后,刘海洋老师在其书《LaTeX入门》中介绍:在TeX内部,绕排工具都是通过\parshape命令和一系列复杂的盒子操作和计算完成的,这也解释了为什么wrapfig在列表环境附近失效的原因(列表环境也依靠\parshape),完全可以通过\parshape产生形状更为复杂的绕排效果,而shapepar宏包的\cutout命令就部分地实现了这一复杂能力,不过具体位置和参数需要手工仔细调整。如果有兴趣,也可以自行去了解一下这个底层命令和这个有趣的宏包。

你的问题描述以及提供的 mwe 都有些复杂,我大概认为你需要:

  1. 文档的各级标题的标题名虽然采用英文字母,但是在必要时正文中能够直接使用汉字;
  2. 目录中包含摘要、插图列表、参考文献等使用\chapter*创建的条目,且需要对这些条目的显示采用自定义内容,并且其字体风格与默认一致;
  3. 正文中插图列表的标题名采用三号居中格式;
  4. 目录中的摘要条目可以跳转到摘要页,而不是PDF首页。

对于第一条,我认为你可能有输入汉字的需要,但是可能并不喜欢 ctex 宏包默认的标题汉化风格。我的方法是改用 xeCJK 支持中文,如果你不用 XeLaTeX ,那么需要其他方法支持中文。

对于第二条,我的方法是使用 tocbibind 宏包,它默认会把章节目录、插图目录、表格目录、参考文献、索引等都加入章节目录,且不用做进一步更改,就能保持默认的字体、字距风格。

对于第三条,在 book 文类中, \listoffigures 以及 \tableofcontents\listoftables\begin{thebibliography}...\end{thebibliography} 在正文中的标题名都是主要通过 \chapter* 命令创建的,容易“改一发而动全身”。要实现同一层级的标题采用不同的字体 、字距风格,我的思路是局部重定义 \listoffigures 的定义 (用分组进行隔离,离开分组就会自动复原)。根据你的文档类,查找 book.cls ,可知 \listoffigures 命令的主要构成是:

\chapter*{\listfigurename}

由于 \chapter* 命令是依据 \chapter命令创建的,而 \chapter 命令的定义的最后一行

\secdef\@chapter\@schapte

意思是:若采用 \chapter命令创建标题,则使用 \@chapter 排版方案;若采用 \chapter*命令创建标题,则使用 \@schapter 排版方案。显然,我们关注后者。查看 \@schapter 的定义:

\def\@schapter#1{\if@twocolumn
                   \@topnewpage[\@makeschapterhead{#1}]%
                 \else
                   \@makeschapterhead{#1}%
                   \@afterheading
                 \fi}

发现其主要依靠 \@makeschapterhead{#1} 这个命令排版 chapter* 。最后,查看 \@makeschapterhead 的定义:

\def\@makeschapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries  #1\par\nobreak
    \vskip 40\p@
  }}

可知,这是 \listoffigures 命令的根源所在,要设置其格式为三号居中,只需要把格式添加在参数 #1 上,也就是说只要能够临时重定义 \@makeschapterhead 就能实现“同是 chapter* 层级的标题,但字体、字距风格不同”的效果。于是可以新定义一个命令,将这个重定义限制在分组内(最好保存原定义,或许有用)。因为涉及内部命令,所以需要更改 @ 字符的类代码。总之,即:

\makeatletter
% 保存原始定义
\let\original@makeschapterhead\@makeschapterhead
% 创建封装环境
\NewDocumentCommand{\mylistoffigures}{}{%
    \begingroup
    \renewcommand{\@makeschapterhead}[1]{%
        \vspace*{50\p@}%
        {\parindent \z@ \raggedright
         \normalfont
         \interlinepenalty\@M
         \centering\fontsize{16bp}{16bp}\selectfont\bfseries ##1\par\nobreak%
         \vskip 40\p@
        }%% 根据 ctex 宏包手册代码实现第 4190 行,汉字三号字的字体尺寸为 16bp ,
    }%%     但是英文字母的三号字是什么尺寸,我不太清楚。总之,你可以改成你喜欢的大小  
    \listoffigures
    \endgroup
}
\makeatother

然后只要在正文中合适的地方,使用 \mylistoffigures 即可产生不同于 \listoffigures 的效果。

对于第四条,上面啸行老师已经给出了解决方案。其实在 tocbibind 的宏包手册中也有描述:
image.png
对此不再赘述。

效果图如下:
image.png
image.png
image.png
image.png

修改过的代码如下:

\documentclass[openany]{book}

\usepackage[papersize={15cm,20cm},margin=.5in]{geometry}

\usepackage{xeCJK}
\setCJKmainfont{SimSun}

\renewcommand{\contentsname}{\textit{Contents}}%% 重定义这些文本宏时若带有格式,会被 tocbibind 带进
\renewcommand{\listfigurename}{List of figures}%% 目录,但是目录本身是不进目录的,所以感觉不到这样做
\renewcommand{\bibname}{References}%%             的效果,可以取消 tocbibind 的选项 nottoc 查看效果

\usepackage[nottoc]{tocbibind}
%\usepackage{tocbibind}

\usepackage{tikz}

\usepackage[colorlinks=true]{hyperref}

\makeatletter
% 保存原始定义
\let\original@makeschapterhead\@makeschapterhead
% 创建封装环境
\NewDocumentCommand{\mylistoffigures}{}{%
    \begingroup
    \renewcommand{\@makeschapterhead}[1]{%
        \vspace*{50\p@}%
        {\parindent \z@ \raggedright
         \normalfont
         \interlinepenalty\@M
         \centering\fontsize{16bp}{16bp}\selectfont\bfseries ##1\par\nobreak%
         \vskip 40\p@
        }%% 根据 ctex 宏包手册代码实现第 4190 行,汉字三号字的字体尺寸为 16bp ,
    }%%     但是英文字母的三号字是什么尺寸,我不太清楚。总之,你可以改成你喜欢的大小 
    \listoffigures
    \endgroup
}
\makeatother

\begin{document}

\title{Title}\author{Author}\date{Date}\maketitle

\phantomsection
\addcontentsline{toc}{chapter}{ABSTRACT}
\centerline{\bfseries ABSTRACT}

My abstract. 

\tableofcontents

\mylistoffigures

\chapter{chapter}
\section{section}\vskip7ex
\begin{figure}[h]
    \centering
    \tikz[scale=.75,every node/.append style={scale=.75}] 
        \foreach \x in {1,...,9} 
        \foreach \y in {1,...,9} 
        \draw (\x,\y) rectangle +(1,1) 
            node at (\x,\y) [shift={(.5,.5)}] {$\x\y$};
    \caption{Some rectangles}
\end{figure}

\chapter{chapter}
\section{section}\vskip7ex
\begin{figure}[h]
    \centering
    \tikz[scale=.75,every node/.append style={scale=.75}] 
        \foreach \x in {1,...,9} 
        \foreach \y in {1,...,9} 
        \draw (\x+.5,\y-.5) circle (.5) 
            node at (\x,\y) [shift={(.5,-.5)}] {$\x\y$};
    \caption{Some circles}
\end{figure}

\begin{thebibliography}{99}
    \bibitem{1} Book A. 
    \bibitem{2} Book B. 
\end{thebibliography}
 
\end{document}

认为有回答符合需求,请点个采纳,谢谢!

image.png

image.png

\documentclass[tikz,border=2pt]{standalone}
\usetikzlibrary{calc,patterns}
\usepackage{amssymb}
\newcommand{\myangleA}{acos(319/480)}%         about              48.4
\newcommand{\myangleB}{180-\myangleA}%         about 180-48.4    =131.6
\newcommand{\myangleC}{\myangleB+2*\myangleA}% about 131.6+2*48.4=228.4
\newcommand{\myangleD}{360+\myangleB}%         about 360+131.6   =491.6
\begin{document}
\begin{tikzpicture}

    \draw [->,very thick] (-.5,0) -- (8,0) node [below] {$x$};% x轴
    \draw [->,very thick] (0,-.5) -- (0,6) node [left]  {$y$};% y轴

    \draw [blue,very thick,dashed]            (.5,.5) rectangle (6.5,5);% 蓝框
    \draw [draw=red,pattern=north west lines] (3,3)   circle    (1.5);% 左圆

    \draw [dashed] ($(5,3)+({\myangleB}:1.2)$) arc ({\myangleB}:{\myangleC}:1.2);% 虚线弧
    \draw          ($(5,3)+({\myangleC}:1.2)$) arc ({\myangleC}:{\myangleD}:1.2);% 实线弧
    
    \node at (0,0)    [below left]                          {$O$};
    \node at (3,3)    [left=9pt,fill=white,rounded corners] {$B$};
    \node at (5,3)    [right=9pt]                           {$S$};
    \node at (6.5,.5) [above left=3pt]                      {$\Lambda$};
    \node at (.5,.5)  [above right=15pt,text=red]           {$\partial B=B_0$};
    \node at (6.5,5)  [above right=9pt]                     {$\mathbb{R}^2$};

\end{tikzpicture}
\end{document}

image.png

发布
问题