2

Given this code, the caption is not centered. If the caption is much shorter, then it is centered. How can I center the (long) caption?

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}[ht]
\hspace*{\fill}
\subcaptionbox{}{
\centering
\begin{tikzpicture}[x=3cm, y=3cm, scale=1.67]
\draw (-.65,0) -- (.65,0);
\end{tikzpicture}
}\hfill
\subcaptionbox{}{
\begin{tikzpicture}[x=3cm, y=3cm, scale=1.67]
\draw (-.15,0) -- (1.15,0);
\end{tikzpicture}
}\hspace*{\fill}
\caption{(a) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\(b)     bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}\label{x}
\end{figure} 
\end{document}

Thank you very much!

1
1

Loading the caption package, I define a hangcentred text format for captions:

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.2pt}
\usepackage{caption, eqparbox}
\DeclareCaptionTextFormat{hangcentred}{\eqparbox[t]{CBox}{#1}}
\captionsetup{ style = base,  format=hang, textformat = hangcentred}

 \begin{document}

 \vspace*{1cm}
\begin{figure}[ht]
\hfill
\subcaptionbox{}{
\centering
\begin{tikzpicture}[x=3cm, y=3cm, scale=1.67]
\draw[red,  very thick] (-.65,0) -- (.65,0);
\end{tikzpicture}
}\hfill
\subcaptionbox{}{
\begin{tikzpicture}[x=3cm, y=3cm, scale=1.67]
\draw[blue,  very thick] (-.15,0) -- (1.15,0);
\end{tikzpicture}
}\hfill\mbox{~}%
\caption{(a) aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\(b) bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb}\label{x}
\end{figure}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy