我有一个很长的图形标题,想将其移动到第一行,如下面的示例图所示。
\def\@dottedtocline#1#2#3#4#5{%
\ifnum #1>\c@tocdepth \else
\vskip \z@ \@plus .2\p@
{\leftskip #2\relax \rightskip
\@tocrmarg \parfillskip -\rightskip \parindent #2\relax
\@afterindenttrue \interlinepenalty \@M \leavevmode
\@tempdima #3\relax
\advance \leftskip \@tempdima \null \nobreak
\hskip -\leftskip {#4}\nobreak
%%% dotfill here
\leaders \hbox {$\m@th \mkern \@dotsep mu\hbox {.}\mkern \@dotsep mu$}
\hfill \nobreak
\hb@xt@ \@pnumwidth {\hfil \normalfont \normalcolor #5}\par }
\fi
}
\renewcommand*{\l@figure}[2]{% #1 = \numberline[number}{text}, #2 = page
\@dottedtocline{1}{2em}{3em}{#1}{#2}%
}
答案1
该解决方案尝试通过使用包定义新列表来模拟您的要求tocloft
。
通过将标题内容插入到与周围材料垂直顶部对齐的位置,可以实现页码所需的对齐,parbox
从而使页码与其内容的第一行对齐。
\documentclass[12pt,a4paper]{article}
\usepackage{showframe} % only to show the margins
% ******************************************* added <<<<<<<<<<<<<<<<<<<
\usepackage{tocloft}% added <<<<<<<<<<<<<<<
\newcommand{\HeadCaptionfigures}{\begin{center}\Large List of Figures \end{center}
\normalfont \normalsize Figure \hfill Page}
\newlistof{Fcaption}{blof}{\HeadCaptionfigures} % \newlistof{<entry>}{<file extension>}{<listofheader>}
\renewcommand{\cftFcaptiondotsep}{\cftnodots} % no dots
\renewcommand{\cftFcaptionafterpnum}{\vspace{1ex}}
\renewcommand{\cftFcaptionindent}{0.5em}% left indent
\addtolength{\cftFcaptionnumwidth}{0.5em} % space after figure number
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\makeatletter
\let\Oldcaption\caption
\newcommand{\Fcaption}[1]
{%
\refstepcounter{Fcaption}
\addcontentsline{blof}{Fcaption}
{\protect\numberline{\thesection.\theFcaption}\parbox[t]{\dimexpr\linewidth-\cftFcaptionindent-\cftFcaptionnumwidth-\@pnumwidth}{\ignorespaces#1}}
\Oldcaption{#1}
}
\makeatother
% *******************************************
\begin{document}
\listofFcaption
\clearpage
\section{Figures}
\begin{figure}[hb!]
\Fcaption{The first caption}
\end{figure}
\clearpage
\clearpage
\begin{figure}
\Fcaption{As any dedicated reader can clearly see, the Ideal of
practical reason is a representation of, as far as I know, the things
in themselves; as I have shown elsewhere, the phenomena should only be
used as a canon for our understanding.}
\end{figure}
\clearpage
\begin{figure}
\Fcaption{The last caption}
\end{figure}
\end{document}
选项类似的方法,但不使用额外的包。我们修补了\caption
命令,因此它也适用于\listoftables.
\documentclass[12pt,a4paper]{article}
\usepackage{showframe} % only to show the margins
% ******************************************* added <<<<<<<<<<<<<<<<<<<
\makeatletter
\renewcommand{\thefigure}{\thesection.\arabic{figure}}
\renewcommand{\thetable}{\thesection.\arabic{table}}
\renewcommand\listoffigures{% header of list to figures
\begin{center}\bfseries \Large List of Figures \end{center}
\normalfont \normalsize Figure \hfill Page\vspace*{1ex}
\@mkboth{\MakeUppercase\listfigurename}{\MakeUppercase\listfigurename}%
\@starttoc{lof}%
}
\newcommand{\@leftindent}{0.5em}% left indent = 0.5em <<<<<<<<<<<<<<<<
\newcommand{\@numberwidth}{2.3em} % figure or table number allocated width <<<<<<<<<<<<<<<<
\renewcommand*\l@figure{\@dottedtocline{1}{\@leftindent}{\@numberwidth}}
\let\l@table\l@figure
\usepackage{xpatch}
\makeatletter
\renewcommand{\@dotsep}{10000}
\xpatchcmd{\@caption}{\ignorespaces #2}%
{\begin{minipage}[t]{\dimexpr\linewidth-\@pnumwidth-\@tocrmarg-\@numberwidth}\ignorespaces#2\vspace*{0.5ex}\end{minipage}}
{}{}
\makeatother
% ******************************************* added <<<<<<<<<<<<<<<<<<<
\begin{document}
\listoffigures
\clearpage
\listoftables
\clearpage
\section{Figures}
\begin{figure}[hb!]
\caption{The first figure caption}
\end{figure}
\clearpage
\begin{figure}
\caption{As any dedicated reader can clearly see, the Ideal of
practical reason is a representation of, as far as I know, the things
in themselves; as I have shown elsewhere, the phenomena should only be
used as a canon for our understanding.}
\end{figure}
\clearpage
\begin{figure}
\caption{The last figure caption}
\end{figure}
\clearpage
\section{Tables}
\begin{table}[hb!]
\caption{The first table caption}
\end{table}
\clearpage
\clearpage
\begin{table}
\caption{As any dedicated reader can clearly see, the Ideal of
practical reason is a representation of, as far as I know, the things
in themselves; as I have shown elsewhere, the phenomena should only be
used as a canon for our understanding.}
\end{table}
\clearpage
\begin{table}
\caption{The last table caption}
\end{table}
\end{document}