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

注册于 2年前

回答
195
文章
0
关注者
9

related link

出现这一现象的原因是ctexrep.cls中定义:
image.png

其中\CTEX@setthispagestyle定义如下,这会将myfancy赋值给了\chapter的原始定义,将原来的\thispagestyle{plain}全部替换为\thispagestyle{myfancy}

image.png

同时又因为\tableofcontents定义中将目录也定义为一个\chapter*,于是导致了“目录的等级应该是和chapter一致的”的现象

\newcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }

要想解决这一问题。可以尝试分离\chapter\chapter*的样式。

OS:我感觉让\chapter样式和ToC中的\chapter*样式分离的需求还蛮常见的,是否有可能让ctex提供ToC/pagestyle的接口选项呢(这也许值得一个issues...我先去翻翻看...有空会提)?

我不太确定这是不是一个好的实践来分离\chapter\chapter*的样式

一个想法是修改\chapter*的样式设置,即下面的代码:
image.png

\documentclass[11pt]{ctexrep}
\usepackage{etoolbox}
\makeatletter
\pretocmd{\@schapter}{\thispagestyle{plain}}{}{}
\makeatother
%自定义样式
\usepackage{fancyhdr}
\fancypagestyle{myfancy}{%
    \fancyhf{}
    \fancyhead[C]{\heiti 毕业设计(论文)}
    \fancyfoot[C]{第\quad \thepage \quad 页}  % 改用 \thepage 显示页码
}
\ctexset{
    chapter/pagestyle=myfancy,
}

\begin{document}
\tableofcontents
\chapter{1}
\chapter{2}
\chapter{1}
\chapter{2}
\chapter{1}
\chapter{2}
\chapter{1}
\chapter{2}
\chapter{1}
\chapter{2}
\chapter{1}
\chapter{2}
\chapter{1}
\chapter{2}
\chapter{1}
\chapter{2}
\end{document}

image.png

当然,这也会修改所有\chapter*{}页面的行为...

个人感觉更好的实践是上面issues中提到的,使用\frontmatter\mainmatter来分划文档的不同部分的样式,但是ctexrap没有提供这几个命令。

Editted Version

也许是一个使用\frontmatter,\mainmatter以及\backmatter划分的例子。

\documentclass[12pt,oneside]{ctexbook}
\usepackage{zhlipsum}
\usepackage{fancyhdr}
\fancypagestyle{myfancy}{%
    \fancyhf{}
    \fancyhead[C]{\heiti 我是\texttt{myfancy}的样式}
    \fancyfoot[C]{第\quad \thepage \quad 页}
}
\fancypagestyle{myfront}{%
    \fancyhf{}
    \fancyhead[C]{\heiti 我是\texttt{myfront}的样式}
}
\fancypagestyle{myback}{%
    \fancyhf{}
    \fancyhead[C]{\heiti 我是\texttt{myback}的样式}
}
% \ctexset{
%     chapter/pagestyle=myfancy,
% }
\begin{document}
\frontmatter
\pagestyle{myfront}
\tableofcontents % 目录页首页由于\chapter*被重置为plain样式

\clearpage
\zhlipsum %其他页码为myfront样式

\mainmatter
\pagestyle{myfancy}

\chapter{111}\zhlipsum \clearpage

\chapter{222}\zhlipsum \clearpage

\backmatter
\pagestyle{myback}
\chapter*{Appendix} % 首页由于\chapter*被重置为plain样式

\zhlipsum[1-5] %其他页码为myback样式

\end{document}

image.png

也可以用你自己用的syntax:cell{}{}={}{}

\documentclass{article}
\usepackage{xcolor}
\usepackage[scale=0.8,papersize={10.5cm,14.85cm}]{geometry}
\usepackage{tabularray}
\pagestyle{empty}
\begin{document}
\begin{center}
    \begin{tblr}{
        hlines,vlines,
        colspec={X[c,m]X[c,m]X[c,m]X[c,m]X[c,m]X[c,m]},
        % cell{3,4}{4,5}={bg=green!30},
        % cell{3,4}{6}={bg=red!30},
        % cell{5,6,7}{6}={bg=blue!30},
        cell{3}{4} = {r=2,c=2}{c,m,bg=green!30},
        cell{3}{6} = {r=2,c=1}{c,m,bg=red!30},
        cell{5}{6} = {r=3,c=1}{c,m,bg=blue!30},
        % stretch = 0,%
    }
        1-1&1-2&1-3&1-4&1-5&1-6\\
        2-1&2-2&2-3&2-4&2-5&2-6\\
        3-1&3-2&3-3&3-4&   &3-6\\
        4-1&4-2&4-3&   &   &   \\
        5-1&5-2&5-3&5-4&5-5&5-6\\
        6-1&6-2&6-3&6-4&6-5&   \\
        7-1&7-2&7-3&7-4&7-5&   \\
    \end{tblr}
\end{center}
\end{document}

多读读文档,其实是有现成的例子抄的~

image.png

image.png

可以使用更加beamer-style的\againframe方法:

\documentclass[notheorems]{beamer}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}
\usepackage{tikz}
\usetikzlibrary{overlay-beamer-styles}

\makeatletter
\resetcounteronoverlays{tcb@cnt@exercise}
\NewTColorBox[auto counter,number within=section]{exercise}{+!O{}}{%
    enhanced,
    /tikz/alt=<1>{colframe=green!20!black}{colframe=red!20!black},
    colback=yellow!10!white,
    /tikz/alt=<1>{coltitle=green!40!black}{coltitle=red!40!black},
    fonttitle=\bfseries,
    underlay={
      \begin{tcbclipinterior}
        \shade[
          alt=<1>{inner color=green!80!yellow}{inner color=red!80!yellow},
          outer color=yellow!10!white
        ] (interior.north west) circle (2cm);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}] (interior.south west) grid (interior.north east);
      \end{tcbclipinterior}
    },
    title={\alt<1>{Exercise~\thetcbcounter:}{Solution of Exercise~\thetcbcounter~on page \pageref{exercise@\thetcbcounter}:}},
    attach title to upper={\alt<1>{\label<1>{exercise@\thetcbcounter}\quad}{\label<2>{solution@\thetcbcounter}\par}},
    after upper={%
      \only<1>{%
        \par\hfill\textcolor{green!40!black}\itshape
        Solution on page~\pageref{solution@\thetcbcounter}
      }
    },
    #1
}
\makeatother

\begin{document}

\begin{frame}<1>[label=quack]%
    \begin{exercise}
      \begin{onlyenv}<1>
        Compute the derivative of the following function:
        \begin{equation*}
        f(x)=\sin((\sin x)^2)
        \end{equation*}
      \end{onlyenv}
      \begin{onlyenv}<2>
        The derivative is:
        \begin{align*}
        f'(x) &= \left( \sin((\sin x)^2) \right)'\\
        &=\cos((\sin x)^2) 2\sin x \cos x.
        \end{align*}
      \end{onlyenv}
    \end{exercise}
\end{frame}%

\againframe<2>{quack}

\end{document}

image.png

@u4830 你所给MWE没有使用markdown语法...

tikz的子库必须使用新版本的TeXLive编译,不可以使用CTeX套装。

关键的问题在于,其中的定义函数名不符合要求,不可以使用数字作为宏的名称(参考阅读):

于是只要将:

\newcommand{\LongitudePlane3}[3]{%
  ...
}

\newcommand{\LatitudePlane3}[3]{%
   ...
}
\newcommand{\DrawLongitudeCircle2}[2]{%
   ...
}
\newcommand{\DrawLatitudeCircle2}[2]{%
   ...
}

中自定义命令末尾的数字3以及2替换为符合要求的即可:
例如:

\newcommand{\LongitudePlaneThree}[3]{%
    \pgfmathsinandcos\sinEl\cosEl{#2}
    \pgfmathsinandcos\sint\cost{#3}
    \tikzset{#1/.estyle={cm={\cost,\sint*\sinEl,0,\cosEl,(0,0)}}}
}

\newcommand{\LatitudePlaneThree}[3]{%
    \pgfmathsinandcos\sinEl\cosEl{#2} % elevation
    \pgfmathsinandcos\sint\cost{#3} % latitude
    \pgfmathsetmacro\yshift{\cosEl*\sint}
    \pgfmathsetmacro\yshift{\cosEl*\sint}
}
\newcommand{\DrawLongitudeCircleTwo}[2]{%
    \LongitudePlane{\angEl}{#2}
    \tikzset{current plane/.prefix style={scale=#1}}% angle of "visibility"
    \pgfmathsetmacro\angVis{atan(sin(#2)*cos(\angEl)/sin(\angEl))} % 
    \draw[current plane] (\angVis:1) arc (\angVis:\angVis+180:1);
    \draw[current plane, dashed] (\angVis-180:1) arc (\angVis-180:\angVis:1);
}
\newcommand{\DrawLatitudeCircleTwo}[2]{%
    \LatitudePlane{\angEl}{#2}
    \tikzset{current plane/.prefix style={scale=#1}}
    \pgfmathsetmacro\sinVis{sin(#2)/cos(#2)*sin(\angEl)/cos(\angEl)}% angle of "visibility"
    \pgfmathsetmacro\angVis{asin(min(1,max(\sinVis,-1)))}
    \draw[current plane] (\angVis:1) arc (\angVis:-\angVis-180:1);
    \draw[current plane, dashed] (180-\angVis:1) arc (180-\angVis:\angVis:1);
}

同时OP提供的代码宏包使用非常混乱,有大量过时老旧的宏包以及大量的重复调用的情况,应该仔细理清每一个提供的具体功能,而不是大量复制代码然后简单堆砌在一起,这是非常不好的习惯,不要不厌其烦地三番五次调用同一个库,很容易导致你大量代码混杂,同时无法提供M(Minimal)WE。你的代码完全可以只通过如下的代码实现:

\documentclass{ctexbook}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\begin{document}

\begin{tikzpicture}[scale=.75]
% Define radius
\def\r{3}

% Bloch vector
\draw (0,0) node[circle,fill,inner sep=1] (orig) {} -- (\r/3,\r/2) node[circle,fill,inner sep=0.7,label=above:$\vec{r}$] (a) {};
\draw[dashed] (orig) -- (\r/3,-\r/5) node (phi) {} -- (a);

% Sphere
\draw (orig) circle (\r);
\draw[dashed,thick] (orig) ellipse (\r{} and \r/3);

% Axes
\draw[->] (orig) -- ++(-\r/5,-\r/3) node[below] (x1) {$x$};
\draw[->] (orig) -- ++(\r,0) node[right] (x2) {$y$};
\draw[->] (orig) -- ++(0,\r) node[above] (x3) {$z$};

%Angles
\pic [draw=gray,text=gray,->,"$\phi$"] {angle = x1--orig--phi};
\pic [draw=gray,text=gray,<-,"$\theta$",angle eccentricity=1.4] {angle = a--orig--x3};

\end{tikzpicture}

\end{document}

image.png

代码可以更短,MWE也应该更短!!!

image.png

正常情况下,#2不需要显式写入\newenvironment的定义中<begin-def>的部分,对于:

\begin{env}
<something>
\end{env}

LaTeX会自动把<something>自动插入到<begin-def><end-def>之间。

区别下面的例子:

\documentclass{article}
\usepackage{tcolorbox}
\newenvironment{tcbA}[2][]{%
\begin{tcolorbox}[#1]
    #2
}{\end{tcolorbox}}
\newenvironment{tcbB}[1][]{%
\begin{tcolorbox}[#1]
}{\end{tcolorbox}}
\begin{document}
    \begin{tcbA}
        Hello, \LaTeX !
    \end{tcbA}
    
    \begin{tcbB}
        Hello, \LaTeX !
    \end{tcbB}
\end{document}

在你的MWE中,因为#2是必须参数,因此\begin{tcbA}在处理时,第一个参数optional argument未指定,所以为默认的<empty>;但是第二个参数mandatory argument缺失,所以TeX先自动吞下(swallow)了一个token H.在<begin-def>命令结束后,之后再把ello, \LaTeX{}的内容作为<something>放进tcb内部。

\fancyhead[CO]{\zihao{5}\rightmark}替换为\fancyhead[CO]{\zihao{5}\makebox[6\ccwd][s]{\rightmark}}

另外你似乎多删除了hyperref宏包的调用。或许可以试试这个:

\documentclass[b5paper,twoside,openany,UTF8]{ctexbook}
\usepackage{fancyhdr}
\usepackage{hyperref}%

\pagestyle{fancy}
\fancyhf{}
\fancyhead[CO]{\zihao{5}\rightmark}
\fancyhead[CE]{\zihao{5}\leftmark}
\fancyfoot[RO,LE]{--~\thepage~--}
\renewcommand{\headrulewidth}{0.5pt} 
\renewcommand{\chaptermark}[1]{%
    \markboth{\texorpdfstring{\makebox[5\ccwd][s]{第\zhnumber{\thechapter}回}}{第\zhnumber{\thechapter}回}}{#1}
}

\fancypagestyle{plain}{%
    \fancyhf{} % 清空页眉页脚
    % 偶数页左下角、奇数页右下角显示页码
    \fancyfoot[RO,LE]{--~\thepage~--}
    \renewcommand{\headrulewidth}{0pt} % 去掉页眉横线
}

\fancypagestyle{frontmatter}{ %frontmatter部分的页眉页脚定制
    \pagestyle{plain} 
    \fancyhf{} 
    \fancyhead[CO]{\zihao{5}\makebox[6\ccwd][s]{\rightmark}}
    \fancyhead[CE]{\zihao{5}\makebox[6\ccwd][s]{这是一本书}}
    \renewcommand{\headrulewidth}{0.5pt} % 确保页眉横线宽度为0.5pt
    \fancyfoot[LE,RO]{--~\thepage~--}  %奇数页右下角、偶数页左下角显示页码
}

\begin{document}
    
    \frontmatter%
    \pagestyle{frontmatter} 
    \pagenumbering{roman}
    \tableofcontents %生成目录

    \mainmatter% 我认为作为一本完整的书
    % \frontmatter \mainmatter \backmatter总是要用好的
    \pagestyle{fancy}
    
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}
    \chapter{title} \chapter{title} \chapter{title} \chapter{title} \chapter{title}    
\end{document}

image.png


BTW,如果追求代码更简洁的话,也许可以把\fancypagestyle缩短,让他继承自plain样式:

\fancypagestyle{frontmatter}[plain]{%frontmatter部分的页眉页脚定制
    \fancyhead[CO]{\zihao{5}\makebox[6\ccwd][s]{\rightmark}}
    \fancyhead[CE]{\zihao{5}\makebox[6\ccwd][s]{这是一本书}}
    \renewcommand{\headrulewidth}{0.5pt} % 确保页眉横线宽度为0.5pt
}

image.png

避免题文不符。

\usepackage{ctex}调用宏包提供中文支持
\documentclass{ctexart}声明文档类,其内部调用了ctex宏包

上面两者是不一样的。

image.png

从这个截图来看,你应该没有指定这个编辑器的编译引擎

ctex宏包或者ctexart文档类均需要xelatex或者lualatex引擎支持。更具体的可见lshort-zh-cn第二章。

考古...

参考自QQ群里Eureka老师给的回答,请看下面的对比。

当然,OP原问题给的代码过长了,提问应该尽量保证代码“最简短”,避免增加阅读障碍。
输出latex3变量和计数器问题显然应该另开两个问题,这样很容易让后来的读者感到混乱迷惑,削弱论坛的信息共享作用。

可以比较下面的例子:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{counter}
\newcounter{cntA}
\newcounter{cntB}
\NewExpandableDocumentCommand{\cmdA}{}
{%
    \thecntA%
    \addtocounter{cntA}{1}
}
\NewExpandableDocumentCommand{\cmda}{}
{%
   okA&\cmdA\\
}
\newcommand{\cmdB}{%
    \thecntB%
    \addtocounter{cntB}{1}
}
\newcommand*{\cmdb}{%
    okB&\cmdB\\
}
\setlength{\parindent}{0pt}
\begin{document}

\begin{tblr}[expand=\expanded]{colspec={|X|X|}}
    \expanded{\cmda}
    \expanded{\cmda}
    \expanded{\cmda}
\end{tblr}

\bigskip

\begin{tblr}[expand=\cmdb]{colspec={|X|X|}}
    \cmdb
    \cmdb
    \cmdb
\end{tblr}
\end{document}

image.png

tblr以及longtblr环境中,有两种展开方式:

  • 直接使用expand=<expandable token>,将直接展开一次
  • 如果使用expand=\expanded后在tblr内部使用\expanded{<expandable token>}进行完全(exhaustive)展开(e-type展开)

而虽然\newcommand\NewExpandableDocumentCommand定义的命令均可展开,但:

  • \newcommand允许只执行部分展开
  • \NewExpandableDocumentCommand要求只能被完全展开

而同时\addtocounter实际上是TeX原语\advance\value{cnt}+1:

\addtocounter: 
macro:#1#2->\@ifundefined {c@#1}{\@nocounterr {#1}}{\global \advance \csname c@#1\endcsname #2\relax }

这是一种assignment过程,属于不可展开的命令,他们因此不应该被放在\NewExpandableDocumentCommand内部。若如此做,将导致该命令变为不可展开类型。

因此在OP的原问题中,tblr环境将会先搜集其内部的所有命令,然后再执行展开\NewExpandableDocumentCommand定义的\cmd(但此时不可展开)。此时使用\expanded{\cmd}将导致直接进行e-type展开将\thecnt完全展开为初始值0.

因此洞察到\addtocounter不可展开,同时在这一情形下仅需要单步展开,决定了应该使用\newcommand以及\expand=\cmd实现.

@u38442 林间花(xxn)老师指出:

你好像传入了这个 \makebox[5\ccwd][s]{第\chinese{chapter}回} 就变成了 [5][s]第一回....
书签使用 \texorpdfstring{⟨TEX 字符串⟩}{⟨PDF 字符串⟩}
同时严厉地指责了我不看hyperref文档的恶劣行为:
image.png

尝试传入chapter/number={\texorpdfstring{...}{...}}即可:

\documentclass[b5paper,twoside,openany]{ctexbook}
\usepackage{zhlipsum}
\ctexset{
    chapter/name = {,},
    chapter/number = {\texorpdfstring{\makebox[5\ccwd][s]{第\chinese{chapter}回}}{第\chinese{chapter}回}},
}
\usepackage[%
    bookmarksnumbered=true,
]{hyperref}
\begin{document}
    \tableofcontents
    \chapter{这是一个标题名1}\zhlipsum[1-6]
    \addtocounter{chapter}{9}
    \chapter{这是一个标题名2}\zhlipsum[1-6]
\end{document}

image.png


测试上一问题评论源代码:

image.png

总是尝试先 最小化代码----定位问题----优先看文档/寻找论坛旧文----解决问题...

非常感谢林间花老师~

考古...

\framebox是水平模式的盒子,其对齐的基线为bottom

可以使用adjustbox...这里有另一个类似的链接

\documentclass{article}
\usepackage{tabularray}
\usepackage{graphicx}
\usepackage{adjustbox}
\begin{document}
\begin{tblr}{
    colspec={X[12em,c]X[10em,c]},
    rowspec={|Q[m]|Q[m]|},
    stretch=0} 
    AAA & BBB\\
    \adjustimage{padding=\fboxsep,frame,width=\linewidth,valign=c}{example-image-duck}
     & $\{x \mid 0<x<4\}$\\
\end{tblr}
\end{document}

image.png

感谢@u64726 提供的思路,微调了一下...

\documentclass[b5paper,twoside,openany,UTF8]{ctexbook}
\usepackage{zhlipsum}
\usepackage{zhnumber}
\ctexset{
    chapter/name = {,},
    chapter/number = {\makebox[5\ccwd][s]{第\chinese{chapter}回}},
}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[CO]{\zihao{5}\rightmark}
\fancyhead[CE]{\zihao{5}\leftmark}
\fancyfoot[RO]{--~\thepage~--}
\fancyfoot[LE]{--~\thepage~--}
\renewcommand{\headrulewidth}{0.5pt} 
\renewcommand{\chaptermark}[1]{%
    \markboth{\makebox[5\ccwd][s]{第\zhnumber{\thechapter}回}}{#1}
}
% 章节首页样式(无页眉和页眉横线,仅保留页码)
% 这是由于在book.cls中,章节首页预定义了样式 \thispagestyle{plain}
% 因此此处重定义 plain 样式相当于重定义了 章节首页
\fancypagestyle{plain}{%
    \fancyhf{}
    \fancyfoot[RO]{--~\thepage~--}
    \fancyfoot[LE]{--~\thepage~--}
    \renewcommand{\headrulewidth}{0pt}
}

\begin{document}
    \tableofcontents
    \chapter{这是一个标题名1}\zhlipsum[1-6]
    \addtocounter{chapter}{9}
    \chapter{这是一个标题名2}\zhlipsum[1-6]
    \addtocounter{chapter}{9}
    \chapter{这是一个标题名3}\zhlipsum[1-6]
\end{document}

image.png

(有没有什么方便的同时展现10+个pdf页面的截图方式啊...上图至少微调了2分钟大小...)

related link

\documentclass[12pt]{ctexart}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage{bm}
\begin{document}

\begin{equation}
    a^2+b^2=c^2
\end{equation}

\begin{empheq}[left={a=\empheqlbrace}]{align}
    \dot{\bm{\lambda}} (t) &= -\frac{\partial H}{\partial \bm{x}}, \label{AA} \\
    \frac{\partial H}{\partial \bm{u}} &= 0, \label{BB} \\
    \dot{\bm{x}} &= \bm{f} (t,\bm{x}, \bm{u}), \notag
\end{empheq}

\begin{equation}
    a^2+b^2=c^2
\end{equation}

\end{document}

image.png

@u64726 Try This and consult for the .log file, by Eureka

\documentclass{article}
\listfiles
\begin{document}
test
\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

REF: https://tex.stackexchange.com/a/45206/294585

TeXLive2024+XeLaTeX一切正常,建议进一步检查宏包版本

可以在导言区使用\listfiles之后在.log文件中找到各个版本。

发布
问题