标题标签居中置于两端对齐的标题文本上方

标题标签居中置于两端对齐的标题文本上方

我希望标题标签(例如图 1)居中显示在一行上,实际标题则在下方对齐。类似这样的

例子

如您所见,借助该caption软件包,我已实现我想要的目标。然而,这会产生

LaTeX Error: Something's wrong--perhaps a missing \item.

对于每个图形。我做错了什么,或者我怎样才能在没有这个错误的情况下实现这个结果?

就像是

\usepackage[labelsep=newline,justification=centerfirst]

某种程度上实现了我想要的并且没有错误,但是文本会跨越整个文本框的宽度。(您怎么称呼它,完全对齐?)这通常会大大降低可读性,我宁愿不使用该选项。

梅威瑟:

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}

%\DeclareCaptionLabelFormat{center}{{\centering #1 #2}}
\DeclareCaptionFormat{center}{{\centering#1#2\\}#3}
\captionsetup{format=center,labelsep=none,justification=justified}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{}
    \caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin quis egestas massa, vitae imperdiet ligula. Curabitur porta luctus orci at congue. Cras luctus blandit velit, quis congue lectus ultricies vel. Quisque non eros ut ante tincidunt mattis sed quis nisi.}
\end{figure}

\end{document}

答案1

\centerline作品:

\documentclass{文章}

\usepackage[demo]{graphicx}
\usepackage{caption}


\DeclareCaptionFormat{center}{{\centerline{#1#2}\\}#3}
\captionsetup{format=center,labelsep=none,justification=justified}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{}
    \caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin quis egestas massa, vitae imperdiet ligula. Curabitur porta luctus orci at congue. Cras luctus blandit velit, quis congue lectus ultricies vel. Quisque non eros ut ante tincidunt mattis sed quis nisi.}
\end{figure}

\end{document}

在此处输入图片描述

答案2

您可以centerlabel按照以下方式定义格式:

\documentclass{article}

\usepackage{graphicx}
\usepackage{caption}

\DeclareCaptionFormat{centerlabel}{%
  \sbox0{#3}%
  \makebox[\linewidth]{\scshape#1#2}\\
  \ifdim\wd0<\linewidth
    \makebox[\linewidth]{\unhbox0}%
  \else
    \unhbox0
  \fi
}
\captionsetup{format=centerlabel,labelsep=none,margin=2cm}

\begin{document}

\begin{figure}[htp]
\centering
\includegraphics[width=\textwidth,height=3cm]{example-image}

\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin quis egestas massa, 
vitae imperdiet ligula. Curabitur porta luctus orci at congue. Cras luctus blandit velit, 
quis congue lectus ultricies vel. Quisque non eros ut ante tincidunt mattis sed quis nisi.}

\end{figure}

\begin{figure}[htp]
\centering
\includegraphics[width=\textwidth,height=3cm]{example-image}

\caption{Very short caption}

\end{figure}

\end{document}

在此处输入图片描述

答案3

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}

\DeclareCaptionFormat{center}{{\centerline{\textsc{#1}#2}\\}#3}
\captionsetup{format=center,labelsep=none,justification=justified}

\begin{document}

\begin{figure}
    \centering
    \includegraphics[width=\textwidth]{}
    \caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin quis egestas massa, vitae imperdiet ligula. Curabitur porta luctus orci at congue. Cras luctus blandit velit, quis congue lectus ultricies vel. Quisque non eros ut ante tincidunt mattis sed quis nisi.}
\end{figure}

\end{document}

两端对齐、居中、小型大写字母

答案4

试试这个。我删除了 \\,使用了 \hfil 和 \par

\DeclareCaptionFormat and added width in the 
\captionsetup

完整代码:

\documentclass{article}

\usepackage[demo]{graphicx}
\usepackage{caption}

%\DeclareCaptionLabelFormat{center}{{\centering #1 #2}}
\DeclareCaptionFormat{center}{{\hfil\textsc{#1}#2\hfil}\par#3}
\captionsetup{format=center,labelsep=none,justification=justified, width=.8\textwidth}

\begin{document}

\begin{figure}
\centering
\includegraphics[width=\textwidth]{}
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin quis egestas massa, vitae imperdiet ligula. Curabitur porta luctus orci at congue. Cras luctus blandit velit, quis congue lectus ultricies vel. Quisque non eros ut ante tincidunt mattis sed quis nisi.}
\end{figure}

\end{document}

在此处输入图片描述

相关内容