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

注册于 2年前

回答
266
文章
0
关注者
11

时隔半年,我尝试了一下...

其实对于大致了解texlive基本语法的用户,从上面的代码微调到texlive支持的样式并不难,但是对于初学者来说,很难分辨如何修改回退。此外你的截图中的需求有一些不合理之处,比如不应该用章节目录来和TOC的对齐情况相比较:

我修改了CCT一些奇怪的设置,在TEXLIVE下一个可行的例子是:

\documentclass[a4paper,twoside,12pt]{ctexbook} 
\renewcommand\baselinestretch{1.414} 
\usepackage{amsmath, amsthm, amssymb, amscd}
\usepackage{makecell,booktabs} 
% \usepackage{float}
\usepackage{mathrsfs}
% \usepackage{latexsym}
\usepackage{setspace}
% \usepackage{makeidx}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{tocbibind}
\usepackage{fancyhdr}
\allowdisplaybreaks
\newtheorem{theorem}{\indent 定理}[section]
\newtheorem{corollary}[theorem]{\indent 推论}
\newtheorem{lemma}[theorem]{\indent 引理}
\newtheorem{proposition}[theorem]{\indent 命题}
\newtheorem{nature}[theorem]{\indent 性质}
\newtheorem{definition}[theorem]{\indent 定义}
\newtheorem{remark}[theorem]{\indent 注记}
\newtheorem{example}[theorem]{\indent 例}
\newcommand{\cndash}{\rule{0.2em}{0pt}\rule[0.35em]{1.6em}{0.05em}\rule{0.2em}{0pt}}
\renewcommand{\proofname}{\bf{\indent 证明}}
\def\Box{\hfill\square}

%%%%%%%%%%%%%%%%%%%
\numberwithin{equation}{section} 
\topmargin=0.5cm
\oddsidemargin=20pt 
\evensidemargin=0pt 
\textwidth=15.1cm
\textheight=22.5cm
%%%%%%%%%%%%%%%%%
\makeatletter 
\def\ps@headings{%
    \def\@oddfoot{\hfill\thepage\hfill}
    \def\@evenfoot{\hfill\thepage\hfill}
    \def\@evenhead{\thepage\hfil\slshape\leftmark}
    \def\@oddhead{\slshape\rightmark\hfil\thepage}
    \let\@mkboth\markboth
    \def\chaptermark##1{%
        \markboth {%                         !!!
            \ifnum \c@secnumdepth >\m@ne
            \if@mainmatter
            \chaptername \ \ %             !!!
            \fi
            \fi
            ##1}{}}%                           !!!
    \def\sectionmark##1{%
        \markright {%                         !!!
            \ifnum \c@secnumdepth >\z@
            \sectionname \ \ %                 !!!
            \fi
            ##1}}}%                             !!!
\renewcommand{\@oddhead}{\protect\footnotesize{%
            \begin{minipage}{\textwidth}
                {\heiti \hfill \ziju{0.5} 家里蹲大学博士学位论文
                    \hfill} \\
                \begin{tabular*}{\textwidth}{@{}l@{\extracolsep{\fill}}r@{}}%
                    {\kaishu \leftmark} & { \kaishu \rightmark}
                    \\ \hline \hline\vspace{2pt}
                \end{tabular*}
            \end{minipage}
    }}
\renewcommand{\@evenhead}{\@oddhead}
\makeatletter 
\@addtoreset{equation}{section} 
\makeatother  
\renewcommand\contentsname{目 \ 录}
\renewcommand\bibname{参考文献}

\begin{document}
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  摘要 %%%%%%%%%%%%%%%    
% \newpage
\pagenumbering{Roman}\thispagestyle{plain}
\chapter*{摘 \ 要}
\addcontentsline{toc}{chapter}{摘 \ \ \ \ 要} 
在第一章中, 我们主要阐述本文所讨论问题的背景及研究现状, 并简要介绍本文的主要工作以及相关的预备知识和一些记号.

\bigskip

\textbf{\zihao{4}\textbf{关键词}:}  临界指数;\ Lusternik-Schnirelman定理.
    
\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% End of 摘要 %%%%%%%%%%%%%%%
\thispagestyle{plain}%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The Abstract of Thesis %%%
\chapter*{Abstract}
\addcontentsline{toc}{chapter}{\large Abstract}
In this thesis, we want to introduce that...

\bigskip

\textbf{\zihao{4}\textbf{Keywords}:}   Lusternik-Schnirelman theory.

\newpage
\thispagestyle{plain}

\tableofcontents

\newpage

\pagenumbering{arabic} 
\setcounter{page}{1}
\chapter{引 言}

本章介绍了与本文所研究课题相关的背景知识, 发展概况以及我们所做的主要工作. 本章介绍了与本文所研究课题相关的背景知识, 发展概况以及我们所做的主要工作.

\section{问题的背景及研究现状} 

\chapter{第一章}

\section{问题的背景及研究现状}

\begin{thebibliography}{99}
\bibitem{ass} AAAA
\bibitem{bss} BBBB
\end{thebibliography}
% %%%%%%%%%%%致谢
\newpage\thispagestyle{empty}\chapter*{\zihao{2} 致 \ \ \ 谢}
\addcontentsline{toc}{chapter}{致\ \ \ \ \ 谢}\bigskip

aaa这里是致谢...
\chapter*{攻读XX学位期间发表的学术论文}
\addcontentsline{toc}{chapter}{攻读XX学位期间发表的学术论文}\vskip 20pt
\begingroup\zihao{4}
\begin{enumerate}[itemsep=15pt]%
    \item 1
    \item 2
    \item 3
\end{enumerate}
\endgroup
\end{document}

image.png

image.png

image.png

image.png

务必要有熟练使用TeXLive语法的功能的能力,才能比较好的用好这种转换,不然很容易一步一卡,非常打击自信心。同时也建议,如非必要,不要使用基于CTeX套装的古早模板。

我还没看你expl3的实现,但是当我们发现在某个模板中lastpage表现异常的时候,我们应该首先在标准文档类中尝试一下lastpage的功能,这样可以确定是文档类设置的冲突问题还是lastpage的问题,@u101077 老师给出的示例已经可以说明,这个问题来源于els-cas-templates模板造成的可能冲突。

同时我们发现els-cas-templates模板已经在TL中包含,因此我们可以做如下的最简测试:

\documentclass{cas-sc}%由于OP的MWE中例子为单列,因此采用`cas-sc`
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{lastpage}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\cfoot{Page~\thepage~of~\pageref{LastPage}}

\begin{document}

\lipsum[1-20]

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{Example image}
\end{figure}

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{Example image}
\end{figure}

\end{document}
els-cas-templates模板定义了lastpage用以显示总页数,但是如果文档最后放置浮动体,则总页数只是有文字的最后一页

一方面....上面的直接调用cas-sc的MWE并无法体现你的问题,所以首先你应该补充基于els-cas-templates的MWE,以体现这一点。

image.png


另一方面关于你写的自我l3实现,很精彩。这里唯一的小瑕疵是patch的时间不对。我想从结果你也能猜出,\lastpage展开为\thepage的时间仅仅是在排版完所有文本(不包括浮动体)所致,在lthooks-doc.pdfltshipout-doc.pdf中我们可以找到应该在浮动体排版结束之后再加入这个patch:
因此我探索出的一个方法是用\AddToHook{shipout/lastpage},这样可以保证在浮动体被浮动算法排版之后再展开\lastpage\thepage:

(我也不是很懂输出例程(output rountine),无法给出更详细的解释...)

但总而言之,修改后的mwe如下:

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}

\makeatletter
\ExplSyntaxOn
\iow_new:N \l_lastpage_file 
\file_if_exist:nTF{\c_sys_jobname_str.page}
{
  \file_input:n{\c_sys_jobname_str.page}
}
{
  \cs_set_eq:NN \lastpage \relax
}
% \AtEndDocument{%
\AddToHook{shipout/lastpage}{%
\iow_open:Nn \l_lastpage_file{\c_sys_jobname_str.page}
\iow_now:Nx \l_lastpage_file 
{
  \cs_set:Npn \exp_not:N \lastpage 
  {
    \thepage
  }
}
\iow_close:N \l_lastpage_file 
}
\cs_new:Npn \__first_foot: 
{ 
  \parbox[t]{\textwidth}
  {~\hfill Page~\thepage{}~of~ \lastpage}
} 
\cs_set_eq:NN \@evenfoot \__first_foot:
\cs_set_eq:NN \@oddfoot \__first_foot:
\ExplSyntaxOff
\makeatother

\begin{document}

\lipsum[1-50]

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{Example image}
\end{figure}

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{Example image}
\end{figure}

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{Example image}
\end{figure}

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{example-image}
    \caption{Example image}
\end{figure}

\end{document}

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

此外我的l3编程经验并不多,而且对于l3file模块也不够了解,但我仍感觉你的这一段实现似乎有点不太符合逻辑:

\file_if_exist:nTF{\c_sys_jobname_str.page}
{%
  \file_input:n{\c_sys_jobname_str.page}
}
{%
  \cs_set_eq:NN \lastpage \relax
}

设想如果一个10页的文档首先被编译,那么.page文档首先展开得到\lastpage=10,如果之后添加了部分内容,这个文档变为15页,但是上面的逻辑仍然会得到\lastpage=10,这反复读取.page似乎不利于多次编译,或者需要用户在第一次编译之后使用latexmk -c删除,我不太明白这一设计的目的是什么,如果已有.page就直接使用(为了节省编译时间咩?)如果我来写的话,我反而会担心这一辅助文件记录了上一次编译的信息,所以应该会是类似这样的删除.page的伪代码思路:

\file_if_exist:nT{\c_sys_jobname_str.page}
{%
  %\file_input:n{\c_sys_jobname_str.page}
  <DELETE FILE> \c_sys_jobname_str.page
}
\cs_set_eq:NN \lastpage \relax

因为我不会改,也与本问题无关,因此我没改动。也希望原题主能解释下这里如此设计的思路,以上...


一个彩蛋...似乎旧版本的lastpage使用的也是\AtEndDocument...我有点感到迷惑,是不是旧版的lastpage.sty就会导致这一问题呢...(所以是我不能复现的原因(?),我的版本是2024-07-07 v2.1c):

image.png

我觉得比较好的方式是用fancyhdr实现.....

单纯使用fancyhdr宏包的实现可以是这样:

\documentclass[fontset=ubuntu]{ctexbook}
\usepackage{geometry}
\usepackage{zhlipsum}
\usepackage{fancyhdr}
\fancyhead[C]{\large\textbf{中~国~科~学~技~术~大~学~博~士~学~位~论~文}\vskip1ex}
\renewcommand{\chaptermark}[1]{%
\markboth{\normalfont\large\CTEXthechapter\quad #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\normalfont\large\textrm{\S\thesection\quad #1}}}
\fancyhead[L]{\leftmark}
\fancyhead[R]{\rightmark}
\fancyfoot[C]{\thepage}
\fancyfoot[L,R]{}
\renewcommand{\headrule}{\hrule height .8pt \vspace*{1mm}\hrule height .8pt\vspace*{1mm}}
\setlength{\headsep}{.5in}
\pagestyle{fancy}
\begin{document}
\chapter{第一章第一章第一章的名字啊啊啊啊}
\section{第一节节名}
\zhlipsum[1-8]
\chapter{第二章第二章第二章的名字啊啊啊啊}
\section{第二节节名}
\zhlipsum[1-8]
\end{document}

image.png

PS. OP的原MWE中出现摘要页部分重叠,是什么情况?你可以自行试试把上面的内容加到你的模板中试试效果😀

image.png

膜拜妮可!! 但是需要注意的是,这个问题如果在要求更高的TSE上很可能是会被closed的。应该尽量避免提出“Do it for me”的问题,这个问题应该分下面两步提

避免让人觉得你是个刚刚打开模板的用户,没有经过任何尝试,然后想"伸手"直接获得这一页眉样式。

  • 问题一:我要实现如下的页眉效果,我已经做了xxx等等如下的尝试(并且贴出你的尝试的代码),但是具体都有yyy的效果不令人满意,只有具体的point才值得被讨论
  • 问题二:从上一个问题中我得到了一个方法,然后我把它加到我正在用的模板中(你可能还要构造新的MWE),然后我发现模板里原先的这一小段设置和问题一的solution具体还存在zzz某点冲突

甩过长的代码上来只会大大降低别人查看并尝试解答的概率。由于以上的原因,尝试合并到你的模板中的事你得自己做了...如有其他问题,请给mwe并提新的提问。

我不能复现你的问题,我的listings版本是v1.10c

\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{listings}
\usepackage[svgnames]{xcolor}
\lstset{
    basicstyle=\ttfamily,
    breaklines=true,
    keywordstyle=\bfseries\color{NavyBlue},
    keywords={as, and, assert, break, class, continue, def, del, elif, else, except, exec, finally, for, from, global, if, import, in, is, lambda, not, or, pass, print, raise, return, try, while, with, yield},
    emph={},
    emphstyle=\bfseries\color{Rhodamine},
    commentstyle=\itshape\color{black!50!white},
    stringstyle=\bfseries\color{PineGreen!90!black},
    columns=flexible,
    numbers=left,
    numbersep=1em,
    numberstyle=\footnotesize,
    frame=single,
    framesep=0em,
}
\begin{document}
\zhlipsum[1]
\begin{lstlisting}[language=Python]
    import matplotlib.pyplot as plt # 绘制图形的库
    from matplotlib_venn import venn2 # 绘制二元韦恩图的库,如果是三元则是 venn3
    plt.figure(figsize=(8, 8)) # 初始化设置图形的尺寸
\end{lstlisting}
\zhlipsum[2]
\end{document}

image.png

请提供你的完整MWE,从\documentclass开始到\end{document}结束。


Editted Version

评论区中下载book.tex删除无关部分之后,新的MWE(也就是你所说的“另一个样子”的\lstset)如下:

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{geometry}
\usepackage{tikz}
\usepackage[dvipsnames]{xcolor}
\usepackage{ctex}
\usepackage{listings}
\lstset{
    basicstyle=\ttfamily, % 设置字体族
    breaklines=true, % 自动换行
    keywordstyle=\bfseries\color{NavyBlue}, % 设置关键字为粗体,颜色为 NavyBlue
    emph=[1]{}, % 指定强调词,如果有多个,用逗号隔开
    emph=[2]{as},
    emphstyle=[1]\bfseries\color{Rhodamine}, % 强调词样式设置
    emphstyle=[2]\bfseries\color{NavyBlue},
    commentstyle=\itshape\color{black!50!white}, % 设置注释样式,斜体,浅灰色
    stringstyle=\bfseries\color{PineGreen!90!black}, % 设置字符串样式
    columns=flexible,
    numbers=left, % 显示行号在左边
    numbersep=1em, % 设置行号的具体位置
    numberstyle=\footnotesize, % 缩小行号
    frame=single, % 边框
    framesep=0em % 设置代码与边框的距离
}
\begin{document}

\begin{lstlisting}[language=Python]
import matplotlib.pyplot as plt # 绘制图形的库
from matplotlib_venn import venn2 # 绘制二元韦恩图的库,如果是三元则是 venn3

plt.figure(figsize=(8, 8)) # 初始化设置图形的尺寸
\end{lstlisting}

\end{document}

在我的电脑上(windows11 TeXLive2024)也正常:
image.png

你应该修改/补充你的问题,给一份尽可能短的,能体现你的as不变色最小工作示例而不是把大段的(几百行的代码)发上来,没人会看。

主要版本差异目前定位于xcolorlistings宏包上

image.png


Bug 复现使用TL20243月版本frozen version的v1.10版本的listings.sty:

image.png


BTW,恭喜你发现了华点.

另外,提供MWE总是能帮助自己和他人方便定位错误的....

图书馆要闭馆惹(逃了逃了)...略微匆忙地用resizebox给了一种缩放&对齐的方法...

\documentclass{book}
\usepackage{amsfonts}
\usepackage{amsmath,amsthm,amssymb,amscd}
\usepackage{graphicx}
\usepackage{ctex}%使用此包可输入中文
\usepackage{tikz}
\usetikzlibrary{patterns}%条纹
\allowdisplaybreaks
\newtheorem{theorem}{\indent 定理}[section]
\newtheorem{remark}[theorem]{\indent 注记}
\makeatletter
\newcommand{\rmnum}[1]{\romannumeral #1}
\newcommand{\Rmnum}[1]{\expandafter\@slowromancap\romannumeral #1@}
\makeatother
\begin{document}

\begin{figure}[htbp]
    \begin{minipage}{.49\textwidth}
        \centering
        \label{tu1}
        \resizebox{\textwidth}{4cm}{%
            \begin{tikzpicture}
            \draw [very thick,-]  (-2.8,3.5) -- (5.8,3.5);
            \draw [very thick,-]  (-2.8,-1.5) -- (5.8,-1.5);
            \path [draw, very thick, ->] node at (-.2,-.2) {$o$} (0,0) -- (2.5,0) node at (2.7,0.2) {$\vec{v}$};
            \path [draw, very thick, ->](0,0) -- (0,1.7)  node[right]  {$\vec{u}$};
            \path [draw, very thick, color=blue, ->] (0,0) -- (2,1.5)
            node at (2.2,1.2) {$x$};
            \node  at (6.5,2.5) {$\mathbb{R}^{2}$};
            \node  at (-1.5,1.5) {{\color{red}$O$}};
            \draw [very thick, color=red,dashed,-] (-2.5,-1) .. controls (-1,-1.5) and (1.5,1)..(5.5,-1.2);
            \draw [very thick, color=red,dashed,-] (-2.5,2) .. controls (-1,1.5) and (1.5,3)..(5.5,2.2);
            \end{tikzpicture}%
        }
        \caption{$\mathbb{R}^{2}$ 上带状示意图}
    \end{minipage}\qquad
    \begin{minipage}{.49\textwidth}
        \centering
        \label{tu2}
        \resizebox{\textwidth}{4cm}{%
        \begin{tikzpicture}
            \path [draw, very thick, ->] node at (-.2,-.2) {$O$} (-0.5,0) -- (8,0) node[anchor=north] {$x$};
            \path [draw,very thick, ->](0,-0.5) -- (0,6.1)  node[anchor=east]  {$y$};
            \node  at (7.5,5.5) {$\mathbb{R}^{2}$};
            \draw[very thick,blue,dashed,-] (0.5,0.5) -- (6.5,0.5) -- (6.5,5) --(0.5,5)--(0.5,0.5);
            \draw[pattern=north west lines] (3,3) circle (1.5);
            \draw [color=red]  (3,3) circle (1.5);
            \node [fill=white,rounded corners,below of=3] at (2.5,4) {$B$};
            \node at (2,1.3) {$ {\color{red}\partial B=B_{0}}$};
            \draw (5,3) circle (1.2);
            \node at (6.2,1) {$\Lambda$};
            \node at (5.5,3) {$S$};
        \end{tikzpicture}
        }
        \caption{$\mathbb{R}^{2}$ 上环绕示意图}
    \end{minipage}
\end{figure}

\end{document}

image.png

另外...你的MWE太长,导言区还是有大量无关信息...

你确实可以通过调整大小(指定width参数)来让浮动算法修改位置:

\documentclass{article}
\usepackage{ctex}
\usepackage{graphicx}
\title{关于近20年的中国GDP数据的描述性统计(2003-2022)}
\author{第二组~乔鑫凯~李梦琪~郭建程}
\date{2月22日}
\begin{document}
\maketitle
箱线图又称为盒须图、盒式图或箱形图,是一种用作显示数据分散情况资料的统计图,因形状如箱子而得名。
下方给出了一个用来反映2003年至2022年中国GDP数据总量分布情况的箱线图
\begin{figure}[hbp]
\centering
\includegraphics[width=.5\textwidth]{example-image}
\caption{箱线图}
\end{figure}

\end{document}

image.png

注意:

  • \author内的空格不会在pdf内体现,可以替换为tier
  • 代码需要提供图片文件,或者用example-image替换(请texdoc mwe),不然在别人的电脑上无法编译
  • 另外\includegraphics{untitled1}[hbp]这个写法是谁教你的...可见群主的介绍,[hbp]是浮动体的参数
  • 请注意保护隐私,代码中有关个人信息部分建议做混淆

@

000 提交文件点击这里:
image.png

提交代码请用围栏代码块语法,或者选中代码文本后点击这里:
image.png

下次提问务必使用围栏代码块把代码包围(不然建议不要提问了)。

做一miumiu补充:

  1. \maketitle应该放在正文部分用于排版封面 \begin{document}之后
  2. \caption应该用于浮动体环境内,请查看lshort-zh-cn的3.9节

PS.若有回答令你满意,请点击采纳此回答。

一个好的例子是这样的:

\documentclass{article}
\usepackage{amsmath}
\usepackage{nicematrix}
% \usepackage{cellspace}
\NiceMatrixOptions{cell-space-limits = 2pt}
\newcommand*{\mi}{\mathrm{i}}
\begin{document}
\[
    \begin{pNiceMatrix}
        1 & 0 & 0 & 0\\
        0 & 1 & 0 & 0\\
        0 & 0 & \dfrac12\left[\displaystyle\sum_{n=0}^\infty\dfrac{(\mi\theta)^n}n+\displaystyle\sum_{n=0}^\infty\dfrac{(-\mi\theta)^n}n\right] & \dfrac1{2\mi}\left[\displaystyle\sum_{n=0}^\infty\dfrac{(\mi\theta)^n}n-\displaystyle\sum_{n=0}^\infty\dfrac{(-\mi\theta)^n}n\right]\\
        0 & 0 & -\dfrac1{2\mi}\left[\displaystyle\sum_{n=0}^\infty\dfrac{(\mi\theta)^n}n-\displaystyle\sum_{n=0}^\infty\dfrac{(-\mi\theta)^n}n\right] & \dfrac12\left[\displaystyle\sum_{n=0}^\infty\dfrac{(\mi\theta)^n}n+\displaystyle\sum_{n=0}^\infty\dfrac{(-\mi\theta)^n}n\right]
    \end{pNiceMatrix}
\]
\end{document}

image.png

@u70101 另外你的mwe并不完整,而且在采纳后理应补充上你使用cellspace的处理方法,不然对于论坛的后来者仍然是一头雾水......

只是好奇,你是否尝试使用过xeCJkfntef宏包的功能呢?

\documentclass[b5paper,twoside,openany,UTF8]{ctexbook}
\usepackage[%    
    left=2.54cm,    %页面左侧页边距
    right=2.54cm,   %页面右侧页边距
    top=2.4cm,     %页面上方页边距
    bottom=2.4cm,  %页面下方页边距
    footskip=1.25cm,    %页脚与文字排版区body下方的距离
    headheight=1.0cm,   %设置页眉高度为1.0cm
]{geometry}%
\usepackage{anyfontsize}
\usepackage[fontsize=12pt]{fontsize}
%====================彩色和带底色高亮文字设定=====================
\usepackage{xcolor}
\usepackage{xeCJKfntef}
\definecolor{lightblue}{rgb}{.8,.8,1}  
\newcommand*\myCJKhl[2][yellow]{\CJKunderanyline*{0.5ex}{\color{#1}\rule{.1pt}{2.5ex}}{#2}}
\begin{document} 
    
以下是测试文字    

你好,三分管森岛帆高水电费计划收到复活甲,对方过后的更好,回到家佛法之上,脚下穿著大红鞋儿,手弄白纱扇儿摇凉。舒服点规划局好,怎破建国饭店。于是乘著酒兴,更多的是下衣,坐在濮耐股份。\myCJKhl[lightblue]{加工费等等评价挂号,屁股方便面出,如好哦平方。一面又将哦巨化绣花鞋儿摘取下来,戏把他韩国队哦给下来,护发诶个,吊打分边西哦架儿上,如是否更换相似,使是否更换,破飞机的,让他加班。规划计先发给寄快递,是否会尽快口,文图机会入繁体,黄金口袋,三个国际化,地方规划局二中好,凤凰国际哦李海峰似。说人家咯,被和规范叫人员不绝。}辅导时间噶发你丰东股份华府国际符号的就开了激发不低哦放大。

\end{document}

image.png

另附cjkhl官方下载链接

cjkhl宏包的直接问题来源为这里

本着解决问题的角度,在2025年,便捷的办法是拥抱xeCJKfntenf。当然,在原始问题下接着留言或者给dpctex提issues是让cjkhl.sty发展的更好的做法,当你搜索到cjkhl时,不要忘记这是一个12年前的宏包。

对于西文文本的下划线,应该使用soul宏包

对于中文文本的下划线,最佳实践是使用xeCJK的子宏包xeCJKfntef,自己自动实现分行,断页

P.S. 提问不要使用截图,请提供代码的文本并放到围栏代码块

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

发布
问题