我怎样才能强制将标题移到长表中的左侧?

我怎样才能强制将标题移到长表中的左侧?

我正在使用 David 的以下建议

在长表内为图形添加标题

我只是想知道如何将标题移到左边,因为我注意到它有时会改变左线。

这是 David 发来的。我需要将标题强制移到左边。

\makeatletter
\def\figcaption{%
    \refstepcounter{figure}%
    \@dblarg{\@caption{figure}}}
\makeatother

我正在我的 longtable 上使用“figcaption”,如提供的链接中所述。

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\usepackage{makecell,multirow,tabularx,booktabs}
\usepackage{longtable}
\usepackage{graphicx}
\usepackage{caption}
\usepackage[showframe=false,,left=2cm,right=2cm,top=2cm,bottom=4.5cm]{geometry}

%this is for figure captions inside a multicolumn/longtable
\makeatletter
\def\figcaption{%
    \refstepcounter{figure}%
    \@dblarg{\@caption{figure}}}
\makeatother
%this is for figure captions inside a multicolumn/longtable

\begin{document}
        %%%%%%%%%%%%%%%%%%START TABLE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{longtable}{|p{2.5cm}p{2.5cm}p{2.5cm}p{2.5cm}p{2.5cm}p{2.5cm}|}
        \captionsetup{singlelinecheck=false}%ADDED HERE
        \endfirsthead

        \multicolumn{6}{r}{\makebox[17cm][r]{\textit{Continuação da página anterior}}}\\ \hline
        \endhead

        \hline
        \multicolumn{6}{r}{\makebox[17cm][r]{\textit{Continua na próxima página}}}\\
        \endfoot
        \endlastfoot

        \hline
        \multicolumn{6}{|l|}{\textbf{Resultado:}} \\
        %inicio da figura
        \multicolumn{6}{|l|}{\parbox{15cm}{
                \includegraphics[scale=0.4]{example-image-a}
                \figcaption{This caption should be on the flushleft and it is not}}}
        \\ %fim da figura
        \multicolumn{6}{|l|}{} \\
        \hline
        \caption{Table A - test caption forced to the left}
    \end{longtable}
\end{document}

在此处输入图片描述

答案1

像这样?

在此处输入图片描述

\documentclass[12pt,a4paper]{article}
 \usepackage[left=2cm,right=2cm,top=2cm,bottom=4.5cm]{geometry}% simplified

\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\usepackage{makecell,multirow,tabularx,booktabs}
\usepackage{longtable}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{labelfont=bf, singlelinecheck=false}% added, had to be here
\captionsetup[table]{singlelinecheck}% added for changing table caption

%this is for figure captions inside a multicolumn/longtable
\makeatletter
\def\figcaption{%
    \refstepcounter{figure}%
    \@dblarg{\@caption{figure}}
    }
\makeatother

\begin{document}
        %%%%%%%%%%%%%%%%%%START TABLE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{longtable}{|p{2.5cm}p{2.5cm}p{2.5cm}p{2.5cm}p{2.5cm}p{2.5cm}|}

        \endfirsthead    
        \multicolumn{6}{r}{\textit{Continuação da página anterior}}\\ \hline
        \endhead    
        \hline
        \multicolumn{6}{r}{\textit{Continua na próxima página}}\\
        \endfoot
        \endlastfoot    
        \hline
        \multicolumn{6}{|l|}{\textbf{Resultado:}} \\
        %inicio da figura
        \multicolumn{6}{|l|}{
                \includegraphics[scale=0.4]{example-image-a}
               \figcaption{This caption should be on the flushleft and it is not}}
        \\ %fim da figura
        \multicolumn{6}{|l|}{} \\
        \hline
        \caption{Table A - test caption forced to the left}
    \end{longtable}
\end{document}

编辑: 对于标题,定义了两个设置,一个用于所有标题,一个用于表格标题的宽度增加。MWE 的结果与以前相同。

答案2

caption这个答案使用了和包的一些功能subcaption。它可能提供一个多功能的解决方案,因为可以进行一系列自定义。我也尝试使用ltcaption包的一些功能,但最终,这里实际上没有实现任何功能。

为简单起见,我删除了与格式化标题和子标题无关的代码。captionltcaptionsubcaption包提供了各自的\captionsetup\captionsetup[longtable]\captionsetup[sub]宏,但正如前面提到的,最后我没有使用\captionsetup[longtable]

图形放置在subfigure环境中,实际上是minipages。使用subfigure环境是使用 的必要条件\subcaption。然后,子标题利用 提供的格式\captionsetup[sub]。由于这指定了justification=raggedright子图的标题设置在左边距。长表标题也使用 的captionsetup方法设置在左边距,但在这种情况下,更可能的是要求标题与表格边缘左对齐,所以我添加了margin=1.75来实现这一点。最终结果是它似乎接近要求。

还可以自定义标题的格式,以冒号作为标题和标题类型(在本例中为表格和子图)之间的分隔符。这些名称也可以使用宏进行自定义\DeclareCaptionLabelFormat。我为表格标题添加了标签格式设置,用葡萄牙语写为 Tabela,对于子图格式,我只使用了 Subfigure。发布的示例表明子图有阿拉伯数字,但我尝试将阿拉伯数字从字母重置为字母,但没有成功。该示例还显示了带有字母标签的长表标题,这是通过 实现的\renewcommand{\thetable}{\Alph{table}}

结果是这样的:

在此处输入图片描述

MWE如下:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[portuguese]{babel}
\usepackage[T1]{fontenc}
\usepackage{longtable,ltcaption,subcaption}
\usepackage{graphicx}
\usepackage[showframe=false,left=2cm,right=2cm,top=2cm,bottom=4.5cm]{geometry}

%\LTcapmarginsfalse % for testing
\setlength\LTcapleft{0pt} % Not working?
\setlength\LTcapright{0pt} % Not working?
\DeclareCaptionLabelFormat{sfcapt}{Subfigure {#2}}
\DeclareCaptionLabelFormat{ltcapt}{Tablea {#2}}
\captionsetup[sub]{labelformat=sfcapt,labelsep=colon,justification=raggedright,singlelinecheck=off}
%\captionsetup[longtable]{labelformat=ltcapt,labelsep=colon,justification=raggedright,singlelinecheck=off,width=1.0\linewidth} %justification not working?
\captionsetup{labelformat=ltcapt,margin=1.75cm,labelsep=colon,justification=raggedright,singlelinecheck=off}
\renewcommand{\thetable}{\Alph{table}}
\renewcommand{\thesubfigure}{\arabic{subfigure}} % Not working?        
\setcounter{subfigure}{1} % Initialize the subfigure counter

\begin{document}
    %%%%%%%%%%%%%%%%%%START TABLE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    \begin{table}[ht]
    \begin{longtable}{|p{3cm}||p{3cm}||p{3cm}||p{3cm}|}
        \hline
        \begin{subfigure}[t]{1.0\linewidth}
        \textbf{Resultado:} \\
        \includegraphics[scale=0.25]{example-image-a} \\
        \subcaption{This caption should be on the flushleft and it is not}
        \end{subfigure}
    &
       \begin{subfigure}[t]{1.0\linewidth}
           \textbf{Resultado:} \\
           \includegraphics[scale=0.25]{example-image-a} \\
           \subcaption{This caption should be on the flushleft and it is not}
       \end{subfigure} 
   &
        \begin{subfigure}[t]{1.0\linewidth}
            \textbf{Resultado:} \\
            \includegraphics[scale=0.25]{example-image-a} \\
            \subcaption{This caption should be on the flushleft and it is not}
        \end{subfigure} 
   & \\

    \end{longtable}
    \setcounter{table}{1} %reset the table counter
    \caption{test caption forced to the left test caption forced to the left}
    \end{table}
\end{document}

相关内容