简体   繁体   中英

LaTeX: Indent subcaption in figure environment

See this MWE:

% !TeX spellcheck = en_US
\documentclass[12pt]{article}
\usepackage[onehalfspacing]{setspace}
\usepackage[a4paper, margin=2.5cm]{geometry}
\usepackage{mathptmx}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[hang]{caption}
\usepackage{subcaption} 
\usepackage[bottom]{footmisc}
\usepackage{dcolumn} %makes r output work
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} 
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}} 
\newcommand{\possessivecite}[1]{\citeauthor{#1}'s (\citeyear{#1})}
\usepackage{pdfpages}
\usepackage{hyperref}
\usepackage{pdflscape}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{landscape}
    \setcapmargin[2cm]

\begin{figure}[]
    \captionsetup{justification=centering}
    \caption{Main Caption. } 
    \label{fig:val_efcts}
    \begin{subfigure}{0.55\textwidth}
        \caption{X}
        \includegraphics[width=\textwidth] {example-image-a}
    \end{subfigure}
    \begin{subfigure}{0.55\textwidth}
        \caption{Y}
        \includegraphics[width=\textwidth] {example-image-b}
    \end{subfigure}
    \begin{subfigure}{0.55\textwidth}
        \caption{Z}
        \includegraphics[width=\textwidth] {example-image-c}
    \end{subfigure}
    \captionsetup{justification=raggedright}    \subcaption*{This subcaption is supposed to be ragged right and intented by 4 cm. \\ This is in a new line.}
\end{figure}

\end{landscape}

\end{document}

It should be self-explanatory, mostly. I'd like the last subcaption below the picture to be ragged right, but indented 2 cm. I tried to use \\setcapmargin, but that does not work, creating the "undefined control sequence" error (so it's an unknown command).

Since you're writing a caption without numbering, set it in a \\parbox where you have some more control over the placement and alignment:

在此处输入图片说明

\documentclass{article}

\usepackage{graphicx}
\usepackage[hang]{caption}
\usepackage{subcaption} 

\begin{document}

\begin{figure}[]
    \captionsetup{justification=centering}
    \caption{Main Caption. } 
    \label{fig:val_efcts}
    \begin{subfigure}{0.3\textwidth}
      \caption{X}
      \includegraphics[width=\linewidth] {example-image-a}
    \end{subfigure}\hfill
    \begin{subfigure}{0.3\textwidth}
      \caption{Y}
      \includegraphics[width=\linewidth] {example-image-b}
    \end{subfigure}\hfill
    \begin{subfigure}{0.3\textwidth}
      \caption{Z}
      \includegraphics[width=\linewidth] {example-image-c}
    \end{subfigure}

    \hspace*{4cm}%
    \parbox{\dimexpr\linewidth-8cm}{\raggedright
    \strut This subcaption is supposed to be ragged right and indented by 4cm. \\
    This is in a new line.\strut%
    }
\end{figure}

\end{document}

Note the use of \\strut s to support correct baseline alignment when dealing with text inside \\parbox es. For more on this, see How to keep a constant baseline skip when using minipage s (or \\parbox es)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM