Sagittarius Rover
Sagittarius Rover
我要成为Typst糕手/(ㄒoㄒ)/~~

注册于 2年前

回答
266
文章
0
关注者
11

对于原OP的MWE:

\documentclass{article}

\newcommand{\foo}{target}%<-mark1

\AddToHook{cmd/foo/before}{extra }%<-mark2
\begin{document}%<-mark3
\foo%<-mark4

\renewcommand{\foo}{new target}%<-mark5
\foo%<-mark6
\end{document}

我来尝试理解一下每一步发生的过程(我希望我的理解没有大问题):

  • mark1:一切照常,定义了新命令\foo
  • mark2:在导言区中使用\AddToHook 由于Hook不会物理性地在导言区存在,而是会有一个延迟修补的机制,在此时增加extra 的内容尚且不会直接被写入\foo的定义中
  • mark3:此时begindocument的钩子自动执行,在此时被延迟写入\fooextra 终于被自动修补\foo的定义中
  • mark4:由于自动修补已经完成,此时输出\foo结果为extra target
因为对于通用钩子在使用\UseHookWithArguments进行自动修补的同时会新建这个钩子,而钩子只能被\NewHook一次,因此可以预见这种自动修补只会进行一次,这里在mark3的时刻,已经由通用钩子cmd/foo/begin的自动修补机制实现了对cmd/foo/begin的创建以及补充代码,故后续不会再进行自动修补
  • mark5:重定义\foo的同时,覆盖了原先的自动修补内容extra .且由于cmd/foo/begin钩子已经存在,不会被再次创建,此时可以使用雾月老师指出的『最佳实践』(也即文档section 2.1.1的第三段):
This has the consequence that a command defined or redefined after \begin{document} only uses generic cmd hook code if \AddToHook is called for the first time after the definition is made, or if the command explicitly uses the generic hook in its definition by declaring it with \NewHookPair adding \UseHook as part of the code.
[kimi翻译版] 这意味着,如果一个命令是在\begin{document}之后定义或重新定义的,只有在定义后首次调用\AddToHook,或者命令在定义时明确使用了通用钩子(通过\NewHookPair声明并包含\UseHook作为代码的一部分),该命令才会使用通用命令钩子代码。

(O.S.我好像没在哪看到\NewHookPair的用法,但这里最后一句的说法我猜就是『最佳实践』的方案)

  • mark6:由于没能再次自动“修补”,此时第二次输出的\foo就仅有最近的一次重定义(\renewcommand)的内容。

对于修改版的MWE:

\renewcommand{\foo}{%
\UseHookWithArguments{cmd/foo/before}{0}%
new target%
\UseHookWithArguments{cmd/foo/after}{0}%
}

要注意的是,如前面介绍,在mark3时已经通过唯一的一次自动修补机制"\NewHook"了一个名为cmd/foo/before的Hook,且其内容为在\foo之前添加extra
于是新的MWE中的\renewcommand里,使用\UseHook{cmd/foo/before}或者\UseHookWithArguments{cmd/foo/before}{0}就可以让cmd/foo/before里保存的内容(因为已经"\NewHook"过这个名为cmd/foo/before的Hook了)“再次”直接发挥作用被\Use,“手动”修补得到想要的结果extra new target.

自行对比。

原来的作者设计\hh的时候是没有考虑到这种直接挖空在段首的情况的

\documentclass[a4paper]{ctexart}
\usepackage[showframe]{geometry}
\usepackage{zhlipsum}
\RequirePackage{xcolor}

\NewDocumentCommand\hha{g}%
{\IfNoValueTF{#1}{\,\underline{\hbox to 1cm{}}\,}{\nolinebreak\textcolor[rgb]{1,0,0}{\underline{#1}}}}

\NewDocumentCommand\hhb{g}%
{\IfNoValueTF{#1}{\,\underline{\hbox to 1cm{}}\,}{\textcolor[rgb]{1,0,0}{\underline{#1}}}}

\begin{document}
    我的答案是什么呢我的答案是什么呢我的答案是什么呢我的答案是什么呢\hha 你好

    我的答案是什么呢我的答案是什么呢我的答案是什么呢我的答案是什么呢\hhb 你好 

  我的答案是什么呢我的答案是什么呢我的答案是什么呢我的答案是什么呢\hha{我能吞下玻璃而不伤身体}

  我的答案是什么呢我的答案是什么呢我的答案是什么呢我的答案是什么呢\hhb{我能吞下玻璃而不伤身体}

  %\hha{我能吞下玻璃而不伤身体}我的答案是什么呢我的答案是什么呢我的答案是什么呢我的答案是什么呢%<---报错

  \hhb{我能吞下玻璃而不伤身体}我的答案是什么呢我的答案是什么呢我的答案是什么呢我的答案是什么呢

\end{document}

image.png

在数学模式中,所有常规的字体默认样式均为斜体

我不太理解你的『教科书』中是什么样子,请截图看看。


Edited:

Thanks to egreg:

\documentclass[tikz]{standalone}
\usepackage{textcomp} % for TS1
\usepackage{amsmath}

\DeclareSymbolFont{textsymbols}{TS1}{\familydefault}{m}{n}
\SetSymbolFont{textsymbols}{bold}{TS1}{\familydefault}{m}{n}

\DeclareMathSymbol{\ulq}{\mathopen}{textsymbols}{39}
\DeclareMathSymbol{\urq}{\mathclose}{textsymbols}{39}
\DeclareMathSymbol{\uprime}{\mathnormal}{textsymbols}{39}

\begin{document}

\begin{tikzpicture}
    \node {\(C' \enspace C\text{\textquotesingle} \enspace \ulq C\urq \enspace C\uprime \)};
\end{tikzpicture}

\end{document}

image.png

Notes:斜体的Cupright single quote感觉很不搭...


Re-Edited:

\documentclass[tikz]{standalone}
\usepackage{amsmath}
\begin{document}

\begin{tikzpicture}
    \node {\(A'B'C' \enspace \mathrm{A}'\mathrm{B}'\mathrm{C}'\)};
\end{tikzpicture}

\end{document}

image.png

另建议把问题描述为:在数学公式中如何输入正体字符....

或者换一个无衬线的数学字体:

\documentclass[tikz]{standalone}
\usepackage{unicode-math}
\setmathfont{Fira Math}
\usepackage{amsmath}
\begin{document}

\begin{tikzpicture}
    \node {\(A'B'C' \enspace \symup{A}'\symup{B}'\symup{C}'\)};
\end{tikzpicture}

\end{document}

image.png

要想全局生效,也可以试试math-style=upright:

\documentclass[tikz]{standalone}
\usepackage[math-style=upright]{unicode-math}
\setmathfont{Fira Math}
\usepackage{amsmath}
\begin{document}

\begin{tikzpicture}
    \node {\(A'B'C'\)};
\end{tikzpicture}

\end{document}

image.png

Have you tried?

image.png

Editted:

Without zhlineskip:

image.png

With zhlineskip:

image.png

似乎可以实现你想要的1.25倍行距(?)

TL25中直接使用latexmk -pdfxe编译确实会出现:

! LaTeX Error: The key 'exam-zh/solution/show-answer' is unknown and is being
(LaTeX)        ignored.

For immediate help type H <return>.
 ...

l.241 }

向上溯源,这个问题报错显然是因为Tl25自带的v0.2.5exam-zh不认识这个key...

USTBexam.cls中,此处写死solution/show-answer = true,,是没有考虑到exam-zh后来的可能更新的...:

% Line 211
\examsetup{
  page = {
    foot-content = {
      \l_ustbexam_title_tl \, 第~\thepage~页 \quad 共~\lastpage@lastpage~页
    },
  },
  sealline = {
    show        = true,
    scope       = mod-2,
    circle-show = false,
    line-type   = dotted,
    odd-info-content = {{装},{订},{线},{内},{不},{要},{答},{题}},

    odd-info-xshift = 12mm,
    text = {自觉遵守考试规则,诚信考试,绝不作弊},% \\装订线内不要答题},
    text-direction-vertical = true,
    text-width = 0.6\textheight,
    text-format  = \normalfont,
    text-xshift = 20mm
  },
  scoringbox/type = onecolumn,
  symbols/change-frac-style = true,
  symbols/change-dfrac-style = true,
  solution/blank-type = hide,
  solution/show-answer = true,
  solution/label-content = 解,
  question/show-answer = true,
  problem/show-answer = true,
  paren/show-answer = true,
  fillin/show-answer = true,
}

进一步回溯,我们发现OP上传的文件信息为:

\ProvidesExplClass {USTBExam} {2022-11-04} {v2.0} {An exam template for USTB}

image.png

开发者在写该.cls此时大概率使用的是TL23自带的v0.1.20前后的版本,我们进一步查看其文档:

由于我没找到v0.1.20.pdf下载链接,用[0.1.23] - 2022-12-20代替: https://gitee.com/xkwxdyy/exam-zh/releases/download/v0.1.24/exam-zh-doc.pdf

在0.2.0版本之前的文档:
image.png

现在TL25时对应0.2.5的文档:
image.png

对于solution/show-answer这一键值对已经发生了更新...这也是为什么报错的原因。

要想解决这一问题,请保持版本依赖的颗粒度对齐

Remarks:

  • 这仅仅是其中一个错误,USTBExam.cls还有多少mismatch...我不知道,我也没有改的任何动机
  • 不再建议使用exam-zhv0.1.x版本,这是USTBExam.cls没有及时随着exam-zh更新的问题,理论上,USTBExam-v2.0从如今来看已经obsoleted,不应该再被使用
  • latexstudio推文的作用是仅仅是做介绍,在2025年下载2023年的推文附件,是有很大的风险的,尤其是上游exam-zh发生了从v0.1v0.2破坏性更新,由此产生的版本错配问题自然由下载者负责...
  • 还发现USTBExam.cls已经更新到v2.3 https://github.com/htharoldht/USTBExam/releases/tag/v2.3.0 你可以自行测试关注下是否已经修复,关于模板问题,请向开发者提issues
  • 关于你在tag中提到的『师生两版』,与本问题无关,建议开新的问题
  • ❗❗❗❗❗标签不要写一大堆东西,简要的宏包或者模板名即可...(我已经第N次提醒) 好好看看正常的tag要怎么写....

image.png

提问请给完整代码....

只给一个切片如何让人知道你所面临问题的全貌....

问题回顾

考古... 你提及:

实现图表既在正文提及处显示,又在文末列表汇总显示

egreg在此处使用寄存器保存figure中的信息,并在文末重新输出:

下面是一个例子:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{environ}

\makeatletter

\let\@@figure\figure
\let\@@endfigure\endfigure
\let\figure\@undefined
\let\endfigure\@undefined

\let\@@table\table
\let\@@endtable\endtable
\let\table\@undefined
\let\endtable\@undefined

\newtoks\end@figuretoks
\newtoks\end@tabletoks

\NewEnviron{figure}[1][htp]{%
  \@@figure[#1]\BODY\@@endfigure
  \global\end@figuretoks=\expandafter{\the\end@figuretoks\@@figure[p]}%
  \global\end@figuretoks=\expandafter{\the\expandafter\end@figuretoks\BODY\@@endfigure}%
  }
\NewEnviron{table}[1][htp]{%
  \@@table[#1]\BODY\@@endtable
  \global\end@tabletoks=\expandafter{\the\end@tabletoks\@@table[p]}%
  \global\end@tabletoks=\expandafter{\the\expandafter\end@tabletoks\BODY\@@endtable}%
  }

\newcounter{Endfigure}
\AtEndDocument{\clearpage\let\c@figure\c@Endfigure\the\end@figuretoks}
\newcounter{Endtable}
\AtEndDocument{\clearpage\let\c@table\c@Endtable\the\end@tabletoks}
\makeatother
\usepackage{lipsum}
\begin{document}
\lipsum

\begin{figure}
\centering
\includegraphics{example-image-a}
\caption{def}
\end{figure}

\lipsum

\begin{figure}
\centering
\includegraphics{example-image-b}
\caption{def}
\end{figure}

\lipsum

\begin{figure}
\centering
\includegraphics{example-image-c}
\caption{def}
\end{figure}

\lipsum

\begin{table}
    \centering
    \begin{tabular}
        { | c | c | c | }
        \hline
        Column 1 & Column 2 & Column 3 \\
        \hline
        Row 1 & Row 1 & Row 1 \\
        Row 2 & Row 2 & Row 2 \\
        Row 3 & Row 3 & Row 3 \\
        \hline
    \end{tabular}
    \caption{table1}
\end{table}

\lipsum

 \begin{table}
        \centering
        \begin{tabular}
            { | c | c | c | }
            \hline
            Column 1 & Column 2 & Column 3 \\
            \hline
            Row 1 & Row 1 & Row 1 \\
            Row 2 & Row 2 & Row 2 \\
            Row 3 & Row 3 & Row 3 \\
            \hline
        \end{tabular}
        \caption{table2}
\end{table}

\end{document}

文档前四面:

image.png

文档中间四面:

image.png

文档末三面:

image.png

BTW...如非必要,不要修改模板。除非你是模板作者...那也不应该问出这样子的问题,应该自行提取MWE再提问...

考古...

好像用0.5\textwidth代替9cm可以解决,但是是什么原理?

正如群主所说,是因为两个minipage的总间距超过了页面版心的宽度。

image.png

这段距离没有超过了两个minipage的总宽度(18cm)...

这同时导致一个警告:

Overfull \hbox (13.88782pt too wide) in paragraph at lines 8--18
[]$[]$ $[]$

一种解决办法是,将距离缩短为(比如8.5cm),并再用\hfill填充距离:

\documentclass{article}
\usepackage{graphicx}
\usepackage[showframe]{geometry}
\usepackage[type=upperleft]{fgruler}
\geometry{margin=2cm}
\begin{document}
\begin{figure}[htbp]
    \begin{minipage}{8.5cm}
        \centering
        \includegraphics[width=8cm]{example-image-a}
        \caption{1}
    \end{minipage}\hfill%
    \begin{minipage}{8.5cm}
        \centering
        \includegraphics[width=8cm]{example-image-b}
        \caption{2}
    \end{minipage}
\end{figure}

\end{document}

image.png

另一种解决办法是你所说的.5\textwidth:

\documentclass{article}
\usepackage{graphicx}
\usepackage[showframe]{geometry}
\usepackage[type=upperleft]{fgruler}
\geometry{margin=2cm}
\begin{document}
\begin{figure}[htbp]
    \begin{minipage}{.5\textwidth}
        \centering
        \includegraphics[width=8cm]{example-image-a}
        \caption{1}
    \end{minipage}
    \begin{minipage}{.5\textwidth}
        \centering
        \includegraphics[width=8cm]{example-image-b}
        \caption{2}
    \end{minipage}
\end{figure}

\end{document}

会得到如下的结果:

image.png

但此时还是有警告(但这时的距离明显缩短了,仅有2.2222pt):

Overfull \hbox (2.2222pt too wide) in paragraph at lines 8--18
[]$[]$ $[]$

如果你说你的眼睛就是尺,你还会发现其实还是没有exactly对齐,这是因为缺少%吞去行末空格导致的。详见这个经典回答

需要在两个minipage之间加上一个%:

\documentclass{article}
\usepackage{graphicx}
\usepackage[showframe]{geometry}
\usepackage[type=upperleft]{fgruler}
\geometry{margin=2cm}
\begin{document}
\begin{figure}[htbp]
    \begin{minipage}{.5\textwidth}
        \centering
        \includegraphics[width=8cm]{example-image-a}
        \caption{1}
    \end{minipage}%%%%注意这里的行末%不可或缺
    \begin{minipage}{.5\textwidth}
        \centering
        \includegraphics[width=8cm]{example-image-b}
        \caption{2}
    \end{minipage}
\end{figure}

\end{document}

image.png

@u134168 请你具体提供你的TeXLive版本信息。您可以在cmd输入tex -v查看版本。

另外,AFAIK,xkeyval以及过时了...

接近四年过去了啊...

首先修改一处小问题:

\lhead{\small{绝密 $\bigstar$ 启用前}}
\cfoot{数学试题第  \thepage 页(共 \pageref{LastPage}页)}

\paageref{}后加一个空格...

\lhead{\small{绝密 $\bigstar$ 启用前}}
\cfoot{数学试题第  \thepage 页(共 \pageref{LastPage} 页)}

image.png

页码显示异常, 有些页面有页码,有些页面没有页码
具体的说是,第3页第6页页码消失
  • 对于第3页的页码,注释下面这两行即可,与上面大佬提供的方法相同(不要在不懂的时候到处复制代码...):
% \thispagestyle{empty} %%%注释

\noindent\textbf{第二部分\  \ 填空题:本部分共4道小题,每个小题~5 分, 共~ 20 分}
        \begin{enumerate}\setcounter{enumi}{12}
                        %\item 设~$z = u^2\ln v$ , 而~$u= \dfrac{x}{y}, v = x-y$ , 则~$\dfrac{\partial z}{\partial x}= $~\underline{~~$\dfrac{2x}{y^2}\ln(x-y)+\dfrac{x^2}{y^2(x-y)}$~~}.
% \thispagestyle{empty} %%%注释
  • 对于第6页的页码 同理
% \thispagestyle{empty} %%%注释
\noindent\textbf{(二)\ \ 选考题:共12分,请考生在第$22\sim23$中任选一道题作答,如果考生多做,则按给出解答的第一题计分.}
\vspace{0cm}

若如此做,可以得到:
image.png

image.png

PS.您这个模板拼接感很重,切忌到处搜罗代码粘贴进去。

提问要让别人能很容易弄懂你的具体问题。

很难搞懂你的问题是这个问题没人回答的一个重要原因。

首先,你的GEEexam.sty已经和零蛋大的官方.sty不一致,属于你的私有模板。而且把哪些部分放到你所说的\endinput之前,也是令人很费解的...

其次,你在本页面提供的GEEexam.sty文件在\endinput之后还加了很多命令,input都结束了你为什么还要加这些命令?是哪里学到的???

我猜你的意思是说,把下面这部分命令:

%以下自定义命令已经粘贴在宏包GEEexam的最后,如果此处删除以下命令,则运行出错
%==============================自定义命令=======================================================
%====填空题横线
\ExplSyntaxOn
\NewDocumentCommand \sh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 0.8cm{}}\,}{\,\underline{\hbox to 0.8cm{\hfill#1\hfill}}\,}}%-------更短横线
\ExplSyntaxOff 

\ExplSyntaxOn
\NewDocumentCommand \hh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 1cm{}}\,}{\nolinebreak\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------短横线
\ExplSyntaxOff

\ExplSyntaxOn
\NewDocumentCommand \hhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 2.5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}
\ExplSyntaxOff
%  用法:\hhh输出_______ ;\hhh{增}输出______增_______;\hhh{\raisebox{.8ex}{$[\frac{\pi}{12},\frac{5\pi}{12}]$}}

\ExplSyntaxOn
\NewDocumentCommand \hhhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------加长横线
\ExplSyntaxOff 

%====阿拉伯数字转罗马数字\rmnum{ }\Rmnum{ }
\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

%====带圈数字2 \circnum{1} 项目编号:[\label=\circnum{\arabic*}]
\newcommand{\circled}[2][]{\tikz[baseline=(char.base)]
    {\node[shape = circle, draw, inner sep = -1pt]%圈大小
    (char) {\phantom{\ifblank{#1}{#2}{#1}}};%
    \node at (char.center) {\makebox[0pt][c]{#2}};}}
\robustify{\circled}
\newcommand{\circnum}[1]{\circled[00]{\footnotesize#1}}%数大小

%====正体数学符号
\newcommand{\R}{\mathrm{\mathbf{R}}}
\newcommand{\N}{\mathrm{\mathbf{N}}}
\newcommand{\Q}{\mathrm{\mathbf{Q}}}
\newcommand{\Z}{\mathrm{\mathbf{Z}}}
\newcommand{\dt}{\,\symup{d} t}
\newcommand{\dx}{\,\symup{d} x}
\newcommand{\dy}{\,\symup{d} y}

%====圆弧\wideparen{ }
\DeclareSymbolFont{ugmL}{OMX}{mdugm}{m}{n}
\SetSymbolFont{ugmL}{bold}{OMX}{mdugm}{b}{n}
\DeclareMathAccent{\wideparen}{\mathord}{ugmL}{"F3}

%====平行四边形\parallelogram
\newcommand*\parallelogram{%
  \mathord{\text{%
    \tikz[baseline]
      \draw (0,.1ex) -- (.8em,.1ex) -- (1em,1.4ex) -- (.2em,1.4ex) -- cycle;}}}

%====平行且相等\paralleleq
\usepackage{pict2e}
\newcommand\paralleleq{%
  \begingroup
  \setlength\unitlength{0.1em}%
  \linethickness{0.5\unitlength}%
  \roundcap
  \mathrel{\begin{picture}(6,7)
    \Line(0,-1)(6,-1)
    \Line(0,0.5)(6,0.5)
    \Line(1.5,1.5)(3.5,7)
    \Line(3.5,1.5)(5.5,7)
  \end{picture}}
  \endgroup}

%====全等\congruent
\newcommand*\congruent{%
    \mathrel{\text{%
    \tikz \draw[baseline] (-.22em,-.4ex) arc (-90:-285:0.4ex) (-.22em,-.4ex) .. controls (0,-.4ex) and (0,.4ex) .. (.22em,.4ex) arc (90:-105:0.4ex) (-.4em,-.75ex) -- (.4em,-.75ex) (-.4em,-1.1ex) -- (.4em,-1.1ex);%
}}}

%====绝对值\abs{ }
\newcommand{\envert}[1]{\left\lvert#1\right\rvert}
\let\abs=\envert

%====列举法表示集合\set
\newcommand\set[1]{\left\{\rule{0cm}{1.7ex} {#1} \right\}}

%====描述法表示集合\Set
\newcommand\Set[2]{\left\{\rule{0cm}{1.7ex}\, {#1} \, \middle\vert \, {#2} \,\right\}}
%=====================================自定义命令结束========================================================

放在main.tex就可行,放在GEEexam.cls内就会报错...

既然你说报错,为什么不提供最短的工作示例,同时提供错误信息呢???

编译你的.sty和删除你所谓“自定义命令”遇到的第一个问题是:

Undefined control sequence.
\@currentHref ->page.\theHpage

我猜这与这个问题有关。

经过测试验证,将

\fancyfoot[C]{\kaishu{}理科数学试题\quad 第\thepage  页 \refstepcounter{page}\quad (共~\pageref{LastPage}~页)\hspace*{13cm} 理科数学试题\quad 第\thepage  页 \quad (共~\pageref{LastPage}~页)}

还原为

\fancyfoot[C]{\kaishu{}理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)\hspace*{13cm} 理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)}

这一关于唯一计数器名称的报错即消失。

我不确定是不是鱼老师修改可能有问题,但还有一个更简单修复办法,在GEEexam.sty官方版本中,有如下被注释的代码:

% Line 22~26
%% =====页眉页脚设置===========================================
%\def\lastfox@putlabel{%
%    \immediate\write\@auxout{%
%        \string\newlabel{LastFox}{{\@arabic\c@foo}{}{}{}{}}}}
%\AtEndDocument{\lastfox@putlabel}

只要同时取消这一段注释,并且使用原来的页码引用方式:

\fancyfoot[C]{\kaishu{}理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)\hspace*{13cm} 理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)}

若如此做,则一切正常

如果看不懂模板,务必不要修改模板的任何设置。

另外,提问务必自己提取MWE(上来就是几百行然后描述也不清晰,这是正确的提问方式吗???),不然没人会看(除非闲的...)。

以下是一个完整的例子:

  • 首先是GEEexam.sty
\ProvidesPackage{GEEexam}[2017/09/27 v1.0 Non-standard LaTeX package]

%% =====添加一些数学环境的宏包==================================
\RequirePackage{amsmath,amssymb}%
\def\dif{\mathop{}\!\mathrm{d}}
\DeclareMathOperator{\rank}{rank}
\RequirePackage{bm}
\RequirePackage{pifont}
\RequirePackage{extarrows} %长等号
\RequirePackage{scalerel}%缩放公式大小
\RequirePackage{array}%m{3em}
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
%% ===========================================================

%% =====设置A3试卷纸张的页边距==================================
\RequirePackage{geometry,calc}
\geometry{a3paper,twocolumn,landscape,hmargin={3.5cm,1.3cm},
vmargin={1.5cm,1.5cm},footskip=0.75cm,headsep=0.25cm}
%% ===========================================================

%% =====页眉页脚设置===========================================
\def\lastfox@putlabel{%
    \immediate\write\@auxout{%
        \string\newlabel{LastFox}{{\@arabic\c@foo}{}{}{}{}}}}
\AtEndDocument{\lastfox@putlabel}

\newcounter{foo}
\newcounter{fox}
\addtocounter{foo}{1}
\RequirePackage{tikz}
\RequirePackage{lastpage}
\newcommand{\defen}[2][1cm]{\hspace*{\fill}\raisebox{-1.1ex}{\tikz\draw[line width=1pt,dash pattern=on 1pt off 2.5pt on 1pt off 2.5pt] (0pt,0pt)--(#1 ,0pt)node[right=-1mm]{(#2~分)};}\newline}
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\setlength{\columnseprule}{0.4pt}
\setlength{\columnsep}{1.8cm}
\fancyfoot[C]{\kaishu{}理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)\hspace*{13cm} 理科数学试题\quad 第\refstepcounter{fox}\thefoo\refstepcounter{foo}页 \quad (共~\ref{LastFox}~页)}

% \fancyfoot[C]{\kaishu{}理科数学试题\quad 第\thepage  页 \refstepcounter{page}\quad (共~\pageref{LastPage}~页)\hspace*{13cm} 理科数学试题\quad 第\thepage  页 \quad (共~\pageref{LastPage}~页)}
\renewcommand{\headrulewidth}{0pt}
%% ===========================================================

%% =====页眉【绝密*启用前】================================
\RequirePackage{color,xcolor}
\RequirePackage{enumitem}
\def\juemi{\noindent{\heiti\zihao{-4} 绝密$\bigstar$启用前}}
\def\biaoti#1{\begin{center}{\zihao{3} #1}\end{center}}
\def\fubiaoti#1{\begin{center}{\zihao{2}\heiti #1}\end{center}}
%% ===========================================================

%% =====设置数学字体为新罗马字体================================
\RequirePackage[T1]{fontenc}
\RequirePackage{mathptmx}
\newfontfamily\TNRBI{Times New Roman Bold Italic} 
\newcommand{\bfit}[1]{\text{\TNRBI #1}} 
%% ===========================================================

%% =====设置大题标题格式=======================================
\ctexset{section = {name = {,、\hspace*{-5mm}},
number = \chinese{section},
format = {\zihao{5}\heiti\raggedright}}}
\ctexset{subsection = {name = {\hspace{5mm},\hspace*{-1mm}},
number = (\chinese{subsection}),
format = {\zihao{5}\heiti\raggedright}}}
\RequirePackage{titlesec}
\titlespacing*{\section}{0pt}{9pt}{4pt}

%% =====选择题选项格式设置====================================
\usepackage{tasks}%选择题宏包,tasks环境
% \settasks{counter-format={tsk[A].},
%               label-offset={0.4em},
%                 label-align=left,
%                 column-sep={2pt},
%                 item-indent={1pt},
%                 before-skip={-0.7em},
%                 after-skip={-0.7em}}
%                 \usepackage{tasks}%选择题宏包,tasks环境
% texlive 2021 用以下设置
%=====================================
\settasks{                           %
    label=\Alph*.,                   %
    label-offset={0.4em},            %
    label-align=left,                %
    column-sep={10pt},               %
    label-width=2ex,                 %
    item-indent={40pt},              %
    before-skip={-0.7em},            %
    after-skip={-0.7em}              %
    }                                %
%=====================================
% 选择题示例 
%\begin{tasks}(4)
%    \task 
%    \task 
%    \task 
%    \task 
%\end{tasks}
%------------------------------ 选择题 ----------------------------------%
%\setcounter{enumi}{12}

\def\tiankongdaan#1{\makebox[3em][c]{#1}}
\newcommand{\blank}[1]{\underline{\tiankongdaan{\qquad~}}}
\DeclareOption{ans}{\renewcommand{\blank}[1]{\,\underline{#1}\,
}}
\ProcessOptions

%------------------------------ 填空题 ----------------------------------%
\ExplSyntaxOn
\NewDocumentCommand \sh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 0.8cm{}}\,}{\,\underline{\hbox to 0.8cm{\hfill#1\hfill}}\,}}%-------加短横线
\ExplSyntaxOff 

\ExplSyntaxOn
\NewDocumentCommand \hh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 1cm{}}\,}{\nolinebreak\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------短横线
\ExplSyntaxOff

\ExplSyntaxOn
\NewDocumentCommand \hhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 2.5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}
\ExplSyntaxOff
%  用法:\hhh输出_______ ;\hhh{增}输出______增_______;\hhh{\raisebox{.8ex}{$[\frac{\pi}{12},\frac{5\pi}{12}]$}}

\ExplSyntaxOn
\NewDocumentCommand \hhhh{g}
  {\IfNoValueTF {#1}{\,\underline{\hbox to 5cm{}}\,}{\nolinebreak\hfill\textcolor[rgb]{1.00,0.00,0.00}{【#1】}}}%-------加长横线
\ExplSyntaxOff 
%% =====自定义数学命令=========================================
% 阿拉伯数字转罗马数字\rmnum{ }\Rmnum{ }
\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother

% 带圈数字2 \circnum{1} 项目编号:[\label=\circnum{\arabic*}]
\newcommand{\circled}[2][]{\tikz[baseline=(char.base)]
    {\node[shape = circle, draw, inner sep = -1pt]%圈大小
    (char) {\phantom{\ifblank{#1}{#2}{#1}}};%
    \node at (char.center) {\makebox[0pt][c]{#2}};}}
\robustify{\circled}
\newcommand{\circnum}[1]{\circled[00]{\footnotesize#1}}%数大小

% 正体数学符号
\newcommand{\R}{\mathrm{\mathbf{R}}}
\newcommand{\N}{\mathrm{\mathbf{N}}}
\newcommand{\Q}{\mathrm{\mathbf{Q}}}
\newcommand{\Z}{\mathrm{\mathbf{Z}}}
\newcommand{\dt}{\,\symup{d} t}
\newcommand{\dx}{\,\symup{d} x}
\newcommand{\dy}{\,\symup{d} y}

%圆弧\wideparen{ }
\DeclareSymbolFont{ugmL}{OMX}{mdugm}{m}{n}
\SetSymbolFont{ugmL}{bold}{OMX}{mdugm}{b}{n}
\DeclareMathAccent{\wideparen}{\mathord}{ugmL}{"F3}

%平行四边形\parallelogram
\newcommand*\parallelogram{%
  \mathord{\text{%
    \tikz[baseline]
      \draw (0,.1ex) -- (.8em,.1ex) -- (1em,1.4ex) -- (.2em,1.4ex) -- cycle;}}}

%平行且相等\paralleleq
\usepackage{pict2e}
\newcommand\paralleleq{%
  \begingroup
  \setlength\unitlength{0.1em}%
  \linethickness{0.5\unitlength}%
  \roundcap
  \mathrel{\begin{picture}(6,7)
    \Line(0,-1)(6,-1)
    \Line(0,0.5)(6,0.5)
    \Line(1.5,1.5)(3.5,7)
    \Line(3.5,1.5)(5.5,7)
  \end{picture}}
  \endgroup}

%全等\congruent
\newcommand*\congruent{%
    \mathrel{\text{%
    \tikz \draw[baseline] (-.22em,-.4ex) arc (-90:-285:0.4ex) (-.22em,-.4ex) .. controls (0,-.4ex) and (0,.4ex) .. (.22em,.4ex) arc (90:-105:0.4ex) (-.4em,-.75ex) -- (.4em,-.75ex) (-.4em,-1.1ex) -- (.4em,-1.1ex);%
}}}

%绝对值\abs{ }
\newcommand{\envert}[1]{\left\lvert#1\right\rvert}
\let\abs=\envert

%列举法表示集合\set
\newcommand\set[1]{\left\{\rule{0cm}{1.7ex} {#1} \right\}}

%描述法表示集合\Set
\newcommand\Set[2]{\left\{\rule{0cm}{1.7ex}\, {#1} \, \middle\vert \, {#2} \,\right\}}

\endinput%%%放最后
  • 用于测试的mwe.tex
\documentclass[11pt,space]{ctexart} 
\usepackage{GEEexam}
\usepackage{zhlipsum}
\begin{document}
        
    填空题横线\hhh
    
    阿拉伯数字转罗马数字~$\Rmnum{3}$
    
    带圈数字~$\circnum{1}$
    
    正体符号~$\R$
    
    圆弧~$\wideparen{AB}$
    
    平行四边形~$\parallelogram$
    
    平行且相等~$\paralleleq$
    
    全等~$\congruent$
    
    绝对值~$\abs{x}$
    
    列举法~$\set{1,2,3}$
    
    描述法~$\Set{x}{1<x<2}$

    \zhlipsum[1-10]

\end{document}

image.png

你问的是对齐。

那你的排版化学式的基本代码(也许是对不齐的情况)为什么不给出

不给测试代码谁能知道你要对齐的是什么东西。

请“补充问题”😖


Edited:

Claim1:我不懂化学,而且我很懒,于是我问了AI给了我几个排版化学式的例子作为示例,我对这些代码不负责

Claim2:本问题关注的是对齐,而不是具体的chemfig如何排版。如果下面的化学式排版有瑕疵,与本问题无关,请自行参照chemfig的文档或者开新的问题;

1.如果你舍得花时间用chemfig实现,一个可能的例子如下:

\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum}
\usepackage{chemfig}
\usepackage[version=4]{mhchem}
\begin{document}
\lipsum[2]

\begin{enumerate}[label=(\arabic*),start=9]
    \item \parbox{\linewidth}{\schemestart
    \chemfig{[:-30]CH_2=CH-CH_2-CH_3}
    \arrow{->[\ce{KMnO4, H2O, \Delta}][\ce{H3O+}]}
    \schemestop}
    \item \parbox{\linewidth}{\schemestart
    \chemfig{*6(-=-=(-CH=CH_2)-=-=)}
    \arrow{->[\ce{O3}]} 
    \chemfig{*6(-=-=(-CHO)-=-=)}
    \arrow{->[\ce{Zn, H2O}]} 
    \chemfig{*6(-=-=(-CH_2OH)-=-=)}
    \schemestop}
    \item \parbox{\linewidth}{\schemestart
    \chemfig{*6(-=-=(-CH_2-CH(CH_3)-OH)-=-=)}
    \arrow{->[\ce{HF}]} 
    \chemfig{*6(-=-=(-CH_2-CH(CH_3)-F)-=-=)}
    \schemestop}
\end{enumerate}

\lipsum[2]
\end{document}

image.png

2.如果你需要插入批量的图片,并且不能提供图片的具体信息特征作为一个完整例子,那自然很难得到最有针对性的回答,也许...

\documentclass{article}
\usepackage{enumitem}
\usepackage{lipsum}
\usepackage{graphicx}
\begin{document}
\lipsum[2]

\begin{enumerate}[label=(\arabic*),start=9]
    \item \parbox{\linewidth}{\includegraphics[width=3cm]{example-image-a}}
    \item \parbox{\linewidth}{\includegraphics[width=4cm]{example-image-b}}
    \item \parbox{\linewidth}{\includegraphics[width=5cm]{example-image-c}}
\end{enumerate}

\lipsum[2]
\end{document}

image.png

提问请务必给最方便别人测试的完整代码。作为一个问如何写代码的问题,不给代码那基本相当于没有问问题。

尝试想在自己的文件中设置题干在左,图片在右的样式

“图文排版”可以使用wrapfig,wrapfig2以及wrapstuff宏包等方式实现。

除此之外,在exam-zh-doc中也提到了text-figure宏包

image.png

使用宏包之前必须看文档问AI你根本无法系统的学习到知识),这意味着你要在终端分别执行:

texdoc wrapfig
texdoc wrapfig2
texdoc wrapstuff

请务必付出实践!!!至少要略读一下文档!!!

这里只给出一个基于wrapstuff的例子(请必须看着wrapstuff的文档来写代码做尝试,而不是无脑问AI最后报错不知所措,或者陷入和AI的扯皮):

\documentclass{ctexart}
\usepackage[a4paper,top=1.5cm,bottom=1.5cm]{geometry}
\usepackage{zhlipsum}
\usepackage{wrapstuff}
\usepackage{graphicx}
\begin{document}
\zhlipsum[2]

\begin{wrapstuff}[r]
    \includegraphics[width=6cm,height=10cm]{example-image}
\end{wrapstuff}
\zhlipsum[1]\wrapstuffclear

\zhlipsum[2]
\end{document}

image.png

至于paracol,你为什么会如此轻信AI的做法,texdoc paracol可以看到,这实际上是用来分栏用的:

image.png

我个人不觉得这是用来实现图文环排的最好办法...

回到你的MWE,所谓“请 AI 帮忙给一个标准的示例”:

  • 第一处警告是缺少中文字符,要输入中文为什么不调用ctex宏包(?)
  • 第二处报错是caption-ofUndefined control sequence.这意味着你需要调用caption或者capt-of宏包

补上之后,你的AI实际上给了你“基础版”和“进阶版”,理应分别测试

“基础版”

\documentclass{ctexart}
\usepackage{paracol}      % 分栏核心包
\usepackage{graphicx}     % 图片支持
\usepackage{lipsum}       % 生成示例文本(实际使用时删除)
\usepackage{capt-of}
\begin{document}

% ========== 基础版(自动等宽分栏)==========
\begin{paracol}{2}  % 数字2表示分两栏

% 左栏(文字部分)
\begin{leftcolumn}
\section{文字标题}
\lipsum[1][1-4]  % 示例文本(替换为实际内容)

\begin{itemize}
    \item 项目列表示例1
    \item 项目列表示例2
    \item 数学公式示例:$E=mc^2$
\end{itemize}
\end{leftcolumn}

% 右栏(图片部分)
\begin{rightcolumn}
\includegraphics[width=\linewidth]{example-image-a} % 使用实际图片路径
\captionof{figure}{图片说明文字}  % 需要 \usepackage{caption}
\end{rightcolumn}

\end{paracol}

\end{document}

image.png

没什么问题。

“进阶版”

\documentclass{ctexart}
\usepackage{paracol}      % 分栏核心包
\usepackage{graphicx}     % 图片支持
\usepackage{lipsum}       % 生成示例文本(实际使用时删除)
\usepackage{capt-of}
\begin{document}

% ========== 进阶版(自定义栏宽+间距)==========
\begin{paracol}[
    columnwidths={0.6\linewidth 0.4\linewidth}, % 左栏60%,右栏40%
    gutter=0.02\linewidth,                      % 栏间距2%
    rulebetween                                 % 显示分栏线(可选)
]{2}

\begin{leftcolumn}
\section{自定义宽度标题}
\lipsum[2][1-3]
\end{leftcolumn}

\begin{rightcolumn}
\includegraphics[width=\linewidth, height=5cm]{example-image-b} % 固定高度
\captionof{figure}{自定义宽度布局示例}
\end{rightcolumn}

\end{document}

确实出现如下报错:

Missing number, treated as zero.
<to be read again>

这说明你使用\begin{paracol}[xxxx]{2}的语法(syntax)有问题...

再次强调!!!

不要轻信AI!!! 看文档!!! 看文档!!!

image.png

image.png

If a \begin{paracol} has the optional numleft argument to specify the number of leading columns nl together with the total n given by num, columns in the environment are laid out across two adjacent pages.

\begin{paracol}的第一个可选参数为[<numleft>],指的是前导列的数量,需要的是一个数,你的AI放进去的是columnwidths={0.6\linewidth 0.4\linewidth},gutter=0.02\linewidth,rulebetween,在文档中根本找不到名为gutterrulebetween的key...

你完全陷入AI的幻觉了,要想用好AI,就不能轻信AI。如果你没有自己对问题的判断力,那你就根本不应该使用AI。

不要轻信AI!!! 看文档!!! 看文档!!!

如果你需要调整比例,也许可以看一下文档的7.3节,提供了\columnratio的命令....

image.png

回到要实现左文右图的排版上来,我个人觉得这些宏包的实践是要优于paracol的:wrapfig,wrapfig2以及wrapstuff。要想学好LaTeX务必学会看文档,轻信AI只会变成AI的奴隶,并且失去自己的核心竞争力。

期待你自行探索wrapfig,wrapfig2以及夏老师的text-figure宏包的使用方法(看文档而不是用AI,比如夏老师的私有宏包text-figure根本没有上传CTAN,AI会的概率微乎其微),自己给出例子。

以上。

可以试试这组参数

xleftmargin=.35em,%
xrightmargin=.35em,%

image.png

image.png

但这是要在geometry宏包不修改左右页面相对距离以及指定文档类的oneside选项的前提下的(如果修改了,这组参数也要做相应修改):

\documentclass[oneside]{ctexbook}
\usepackage{zhlipsum}
\usepackage[showframe]{geometry}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{titlesec}
\titleformat*{\section}{\makebox[\textwidth][c]} 
\titleformat{\section}[frame]
    {\color{magenta}}
    {\centering\footnotesize\enspace 节 \thesection\enspace}
    {8pt}
    {\bfseries\filcenter\songti}
    [\vspace{-10pt}]

\usepackage{listings}
\usepackage{xcolor}

\lstdefinelanguage{VBA}{
    morekeywords={Sub, End, Dim, As, Set, Range, Worksheet, MsgBox, If, Then, Else, For, Next, Do, While, Loop, Integer, String},
    sensitive=true,
    morecomment=[l]{'},
    morestring=[b]{"},
    keywordstyle=\color[HTML]{0184bc},
    stringstyle=\color[HTML]{41a977},
    basicstyle=\small\ttfamily,
    keepspaces=true,
    numbers=left,
    columns=fullflexible,
    xleftmargin=.35em,%
    xrightmargin=.35em,%
}

\lstset{
    language=VBA,
    frame=single,
    linewidth=\dimexpr\textwidth\relax,
    escapeinside=``
}

\begin{document}
\section{初步}
\begin{lstlisting}[caption={生成斐波那契数列},label={code:fib}]
'To generate the Fib Sequence
Sub GenerateFibonacci()
\end{lstlisting}
\end{document}

你的代码这么长(足足有116行),你觉得他是最小工作示例吗?

  • 如果你注释你的代码块的内容,问题仍然存在,这说明代码块内容可以简化为Hello, World!,缩短20行
  • 这说明与lisitngs宏包无关,同时再把你有关\lstset设置全删了,缩短50行
  • 删到最终你会发现,连下面的例子都报错:
\documentclass{ctexbook}
\usepackage{geometry}
\ctexset{
    chapter = {
        name = {\S},   % 将"第X章"改为"§ X"
        number = \arabic{chapter},    % 阿拉伯数字编号
        format = \songti\large\bfseries\centering, % 标题格式
        beforeskip = 2.5ex,          % 标题前间距
        afterskip = 2.5ex,           % 标题后间距

      }
 }

\begin{document}

\chapter{哈哈哈}
\section{初步}
Hello, World!

\end{document}

为什么要不负责任地把大段的代码贴上来增加别人的阅读量

答案你也知道了... 第一个问题是\ctexset内不能有空行...

LaTeX不是python,不能想空行就空行,每一个空格,每一个~甚至注释符号%都有其作用,必须每一步都谨小慎微。

希望下次不要再看到100+行的最大工作示例。

删去空行之后,第二个问题是

\chapter{哈哈哈}
Not allowed in LR mode.

从原来的代码再次删,不难发现,这段代码一加就报错:

\renewcommand{\contentsname}{%
  \begin{center}
    \normalfont\songti\bfseries 文章目录
  \end{center}
}

这又是为什么呢?原因就是Not allowed in LR mode.....

附第二份MWE:

\documentclass{ctexbook}
\usepackage{zhlipsum}
\usepackage{titletoc}
\usepackage{titlesec}
\usepackage{geometry}
\usepackage{fontspec}
\geometry{a4paper,centering,scale=0.9}
\renewcommand{\contentsname}{%
  \begin{center}
    \normalfont\songti\bfseries 文章目录
  \end{center}
}

\begin{document}

\tableofcontents

\chapter{哈哈哈}

\section{初步}

\end{document}

理论上提取MWE的操作不需要任何LaTeX技能,甚至来个小学生不断二分编译都能提取出来....只是因为大家的代码太长....都懒....

这些都是哪里学的....请使用@u79794 老师提供的方法....

你显然应该每加一个设置就编译,如果报错找问题,没报错再进行下一个配置。你一开始面临的代码存在多处问题,这些问题互相影响,让你的代码很难debug....

发布
问题