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

注册于 2年前

回答
273
文章
0
关注者
11

related link

\documentclass{beamer}
\usetheme{Berlin}
\usepackage{ctex}
\usepackage{amsmath}
\usefonttheme{serif}
\usepackage{cleveref}
\usepackage{hyperref}
\crefformat{equation}{#2式~(#1#3)}

\let\chyperref\cref
\renewcommand{\cref}[1]{{\hyperlink{#1}{\chyperref{#1}}}}

\begin{document}

\section{问题重述}
\begin{frame}{问题重述}
    这是上帝公式
    \begin{equation}
        \mathrm{e}^{\mathrm{i}\pi}+1=0
        \label{eq:1}
    \end{equation}
\end{frame}

\begin{frame}
    \cref{eq:1}是最美的公式。
\end{frame}

\end{document}

另外,原始MWE带来的警告与这个问题似乎是相同的...

The beamer document class redefines the \label command in a particularly devious way...

我觉得你不应该用计数器proof以及\theproof的值来控制长度。

另外我没看懂『前后无间距以使得悬挂缩进可以实现』,以及subsize是想实现什么...

如果你需要『悬挂缩进』,其实latex2e是有类似的quote环境的:

image.png

%article.cls
\newenvironment{verse}
               {\let\\\@centercr
                \list{}{\itemsep      \z@
                        \itemindent   -1.5em%
                        \listparindent\itemindent
                        \rightmargin  \leftmargin
                        \advance\leftmargin 1.5em}%
                \item\relax}
               {\endlist}
\newenvironment{quotation}
               {\list{}{\listparindent 1.5em%
                        \itemindent    \listparindent
                        \rightmargin   \leftmargin
                        \parsep        \z@ \@plus\p@}%
                \item\relax}
               {\endlist}
\newenvironment{quote}
               {\list{}{\rightmargin\leftmargin}%
                \item\relax}
               {\endlist}

另外,代码要给完整...同时最好详细描述proof以及subsize想达到的预期效果示意图。

提供代码要完整,可编译。

一个也许你的复现如下:

\documentclass{article}
\usepackage[a4paper,showframe]{geometry}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{xcolor}
\begin{document}
\begin{figure}[h]
    \centering
    \caption[Sparse-SIM resolves known structures of ~60 nm in size.]{Sparse-SIM resolves known structures of ~60 nm in size.}
    \includegraphics[width=.6\linewidth]{example-image}
    \begin{minipage}{\textwidth}
    {\color{red}\textbf{This is the table notes}}\\
    \lipsum[1-6]%
    \end{minipage}
\end{figure}
\end{document}

image.png

那你确实要么只能缩小字体,要么只能压缩内容。

提问必须提供完整的MWE。

确实如此,请查看texdoc amsthm的文档。

image.png

\documentclass{article}
\usepackage{amsthm}
\newtheorem{mythmA}{ThmA}
\theoremstyle{definition}
\newtheorem{mythmB}{ThmB}
\setlength{\parindent}{0pt}
\begin{document}

This is a theorem with a custom label.

\begin{mythmA}
This is a theorem with a custom label.
\end{mythmA}

\begin{mythmB}
This is a theorem with a custom label.
\end{mythmB}

This is a theorem with a custom label.

\end{document}

image.png

考古....

一个比较方便的办法是使用paracol提供的\columnratio{.6667}:

\documentclass{article}
\usepackage{microtype}
\usepackage[a4paper,margin=1in]{geometry}
\usepackage{paracol}
\usepackage{lipsum}
\usepackage{graphicx}
\columnratio{.6667}

\begin{document}

\begin{paracol}{2}
\lipsum[1-5]
\switchcolumn
\lipsum[1]

\noindent\includegraphics[width=5cm]{example-image}

\lipsum[2]
\end{paracol}

\end{document}

image.png

提问必须要给最小工作示例

希望上下两行的能够换行的答题线长度之和是定值,暂定为9em,考虑到通用性,希望可以指定任意合理的长度

不完全符合OP的需求,但也许可以借用xeCJkfntef提供的hidden选项,用多个之间的间隙来实现自动换行。

\documentclass{ctexart}
\usepackage[showframe,margin=1in]{geometry}
\usepackage{enumitem}
\setlist[enumerate]{nosep,labelsep=0pt,leftmargin=2em}
\usepackage{multicol}
\setlength{\columnseprule}{.4pt}
\setlength{\columnsep}{1cm}
\usepackage{xeCJKfntef}
\newcommand{\gentext}[2][啊]{%
    \ifnum#2>0\relax%
        #1\gentext{\numexpr#2-1}\unskip%
    \fi%
}
\newcommand*{\myrule}[2][.4pt]{%
    \CJKunderline[hidden,thickness=#1]{\gentext{#2},\gentext{#2}}
}
\begin{document}

\noindent\textbf{16. }补写出下列句子中的空缺部分。(6分)

\begin{multicols}{2}

\begin{enumerate}[label=(\arabic{enumi})]
    \item 
    王湾《次北固山下》的名句“\myrule{5}”,描写时序交替中的景物,暗示着时光流逝,蕴含着自然理趣。
    \item 
    小慧为朋友家的农家乐餐厅写宣传横幅,直接使用了陆游《游山西村》里的“\myrule{7}”两句诗,朋友看了觉得很贴切。
    \item 
    行至群山深处,见到一挂瀑布飞泻而下,水石激荡,轰鸣作响,于老师回头对学生们说:“这不就是古诗中写的‘\myrule{9}’嘛!”
\end{enumerate}

\end{multicols}

\noindent\textbf{参考答案:}

\begin{enumerate}[label=(\arabic{enumi})]
    \item 
    海日生残夜\quad 江春入旧年
    \item 
    山重水复疑无路\quad 柳暗花明又一村
    \item 
    飞流直下三千尺\quad 疑是银河落九天(飞湍瀑流争喧豗\quad 砯崖转石万壑雷)
\end{enumerate}

\end{document}

image.png

也许可以试试amsmath提供的flalign,找好合适的对齐点位。

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{flalign}
\max\enspace &\sum_{i=1}^np_if_i(s_i)&\mathrm{(3-1)}&& \\
\mathrm{s.t.}\enspace&\sum_{j=1}^{n+1}x_{0,j}=\sum_{i=0}^{n}x_{i,n+1}=1,&\mathrm{(3-2)}&& \\
&\sum_{j=0,j\neq i}^nx_{j,i}=\sum_{j=1,j\neq i}^{n+1}x_{i,j}=y_i,&\mathrm{(3-3)}&& \\
&\sum_{i=1}^{n}s_{i}+\sum_{i=0}^{n}\sum_{j=1}^{n+1}t_{ij}x_{ij}\leq T_{\max},&\mathrm{(3-4)}&& \\
&s_{i}\leq\tau_{i}y_{i},&\mathrm{(3-5)}&& \\
&1\leq z_{i}\leq n,&\mathrm{(3-6)}&& \\
&z_{i}-z_{j}+1\leq n(1-x_{ij}),&\mathrm{(3-7)}&& \\
&x_{ij}\in\{0,1\},&\mathrm{(3-8)}&& \\
&y_{i}\in\{0,1\},&\mathrm{(3-9)}&& \\
&s_{i}\geq0,&\mathrm{(3-10)}&&
\end{flalign}
\end{document}

image.png

Editted:

BTW,如果想要求和号都对齐,还可以用mathtools宏包的\mathclap:
image.png

感兴趣的自己看看文档吧~可以实现如下效果...

image.png

对于原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.


非常感谢雾月老师,同时也有必要再补充一点以方便我的理解:

对于OP已提及的『尝试过的做法』:在\renewcommand之后再次\AddToHook:

\documentclass{article}
\newcommand{\foo}{target}
\AddToHook{cmd/foo/before}{extra }%
\begin{document}%
\LogHook{cmd/foo/before}%First
\foo%

\renewcommand{\foo}{new target}%
\AddToHook{cmd/foo/before}{extra }%
\LogHook{cmd/foo/before}%Second

%因为hookname已经被占用,不会自动修补
\foo% 因此在『已进行的尝试』中同样无效

\UseHook{cmd/foo/before}%
\foo%

% 其实就等价于『最佳实践』的做法,当需要对重定义命令多次Hook时,手动把`\UseHook'写入`\renewcommand'
\end{document}

image.png

第一处LogHook结果:

-> The generic hook 'cmd/foo/before':
> Code chunks:
>     ---
> Document-level (top-level) code (executed last):
>     -> extra 
> Extra code for next invocation:
>     ---
> Rules:
>     ---
> Execution order:
>     ---.

第二处LogHook结果,但因为不会第二次自动修补,进而不生效:

-> The generic hook 'cmd/foo/before':
> Code chunks:
>     ---
> Document-level (top-level) code (executed last):
>     -> extra extra 
> Extra code for next invocation:
>     ---
> Rules:
>     ---
> Execution order:
>     ---.

Happy Hooking!

自行对比。

原来的作者设计\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以及过时了...

发布
问题