LaTeX中使用\@author命令致图题错位,求解决及替代方案
一、为什么@author会引发图题错位
authblk包的\@author是为标题页设计的内部命令,输出作者信息时会修改全局排版参数(比如段落缩进、浮动体标题的缩进规则等),且这些修改不会自动恢复,进而干扰后续所有图、表的标题布局,导致错位。
二、修复@author导致的图题错位
将\@author的输出限制在局部环境中,避免修改全局参数,示例代码如下:
\documentclass{report} \usepackage{authblk} \usepackage{graphicx} % 定义作者和机构 \author[1]{张三} \affil[1]{某大学计算机学院} \author[2]{李四} \affil[2]{某人工智能研究院} \begin{document} \chapter{引言} % 将\@author包裹在parbox中,限制作用范围 \par\vspace{1em} \parbox{\linewidth}{% \makeatletter \@author \makeatother } \par\vspace{1em} \begin{figure}[h] \centering \includegraphics[width=0.6\textwidth]{example-image} \caption{示例图:测试图题排版} \end{figure} \end{document}
原理:\parbox{\linewidth}把作者信息的输出限制在固定宽度的盒子内,\@author修改的参数仅在盒子内部生效,不会影响后续浮动体标题。
三、不使用@author和\maketitle的替代方法
方法1:自定义命令提取authblk的作者信息
直接调用authblk的内部变量自行排版作者列表,避开\@author:
\documentclass{report} \usepackage{authblk} \usepackage{graphicx} \author[1]{张三} \affil[1]{某大学计算机学院 | zhangsan@example.com} \author[2]{李四} \affil[2]{某人工智能研究院 | lisi@example.com} % 自定义打印作者的命令 \makeatletter \newcommand{\printChapterAuthors}{% \par\vspace{1em} {\large \textbf{作者及机构:}}\par % 遍历作者列表 \@for\@auth:=\@authorlist\do{% \@auth \par } % 遍历机构列表 \@for\@affil:=\@affillist\do{% \quad \textit{机构:} \@affil \par } \par\vspace{1em} } \makeatother \begin{document} \chapter{引言} \printChapterAuthors \begin{figure}[h] \centering \includegraphics[width=0.6\textwidth]{example-image} \caption{示例图:测试图题排版} \end{figure} \end{document}
方法2:完全自定义作者排版(不依赖authblk内部变量)
如果不需要复用全局作者信息,可直接在章节内手动排版,或定义独立变量:
\documentclass{report} \usepackage{graphicx} % 定义全局作者变量 \newcommand{\currentChapterAuthors}{张三、李四} \newcommand{\currentChapterAffils}{% 1. 某大学计算机学院 \par 2. 某人工智能研究院 } \begin{document} \chapter{引言} \par\vspace{1em} {\large \textbf{作者:}} \currentChapterAuthors \par {\large \textbf{所属机构:}} \par \currentChapterAffils \par\vspace{1em} \begin{figure}[h] \centering \includegraphics[width=0.6\textwidth]{example-image} \caption{示例图:测试图题排版} \end{figure} \end{document}
方法3:使用titling包灵活控制章节作者
titling包可脱离\maketitle单独处理作者信息排版:
\documentclass{report} \usepackage{titling} \usepackage{authblk} \usepackage{graphicx} \author[1]{张三} \affil[1]{某大学计算机学院} \title{} % 无需标题页,设置空标题 % 重置titling的默认格式,避免生成标题页 \pretitle{} \posttitle{} \preauthor{} \postauthor{} % 自定义带作者的章节命令 \newcommand{\chapterWithAuthor}[1]{% \chapter{#1} \par\vspace{1em} {\large \theauthor \par \textit{机构:} \theaffil}\par \vspace{1em} } \begin{document} \chapterWithAuthor{引言} \begin{figure}[h] \centering \includegraphics[width=0.6\textwidth]{example-image} \caption{示例图:测试图题排版} \end{figure} \end{document}
内容的提问来源于stack exchange,提问作者Koalabear
相关产品推荐
相关产品推荐

