如何在長表中強制將標題置於左側?

如何在長表中強制將標題置於左側?

我正在使用大衛的以下建議

在長表內的圖形中加入標題

我只是想知道如何將標題放在左側,因為我注意到它有時會改變左線。

這是大衛發來的。我需要將標題強制移到左側。

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

我在我的長桌上使用“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,但最終這裡沒有實際實現。

為了簡單起見,我刪除了與格式化標題和副標題無關的程式碼。caption,ltcaption和包subcaption提供了各自的\captionsetup,\captionsetup[longtable]\captionsetup[sub]宏,但正如已經提到的,最終我沒有使用\captionsetup[longtable].

這些人物被放置在subfigure實際的環境中minipages。使用subfigure環境是使用的要求\subcaption。然後,子標題將使用 提供的格式\captionsetup[sub]。因為這指定了justification=raggedright子圖的標題設定在左邊距。使用該方法也將長表標題設置在左邊距captionsetup,但在這種情況下,更有可能要求標題與表格邊緣左對齊,因此我添加了這一點margin=1.75來實現這一點。最終的結果是它看起來接近要求。

也可以自訂標題的格式,以提供冒號作為標題和標題類型(在本例中為表格和子圖)之間的分隔符號。這些名稱也可以使用\DeclareCaptionLabelFormat巨集進行自訂。我為表格標題添加了標籤格式設置,用葡萄牙語編寫為 Tabela,對於子圖格式,我只使用了 Subfigure。發布的範例表明子圖具有阿拉伯編號,但我嘗試從阿拉伯字母重置編號的嘗試沒有成功。該範例還顯示了帶有 alpha 標籤的 longtable 標題,這是透過\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}

相關內容