并排 tcolorbox 中的标题对齐

并排 tcolorbox 中的标题对齐

在下面的图片中,如何使两个标题水平对齐,同时保持两个图的顶部对齐不变?

在此处输入图片描述

\documentclass[draft]{article}
    \usepackage{tcolorbox,caption}
    \tcbset{sidebyside,
            center upper,
            center lower,
            colbacktitle=red!50,
            coltitle=black,
            fonttitle=\sffamily\bfseries\large}
    \begin{document}
        \begin{tcolorbox}[sidebyside align=top seam,
                        title=The captions are not aligned]
                \includegraphics{file1.png}
                \captionof{figure}{file1}
            \tcblower
                \includegraphics[scale=1.5]{file2.png}
                \captionof{figure}{file2}
        \end{tcolorbox}
        \vspace{2cm}
        \begin{tcolorbox}[sidebyside align=bottom seam,
                        title= The figure's top borders are not aligned
                        ]
                \includegraphics{file1.png}
                \captionof{figure}{file1}
            \tcblower
                \includegraphics[scale=1.5]{file2.png}
                \captionof{figure}{file2}
        \end{tcolorbox}

    \end{document}

答案1

在这种情况下,我认为最好避免sidebyside使用选项,而使用tabularx内部tcolorbox来组织图形和标题,或者在内部tcboxedrastertcboxeditemize使用等高行声明它们。

\documentclass[draft]{article}
\usepackage[most]{tcolorbox}
\usepackage{capt-of, tabularx}

\newcolumntype{Y}{>{\centering\arraybackslash}X}
\tcbset{colbacktitle=red!50,
        coltitle=black,
        fonttitle=\sffamily\bfseries\large}
\begin{document}
\begin{tcolorbox}[title=The captions are not aligned]
    \begin{tabularx}{\linewidth}{YY}
        \vspace{0pt}\includegraphics{file1.png} & 
        \vspace{0pt}\includegraphics[scale=1.5]{file2.png}\\
      \captionof{figure}{file1} &\captionof{figure}{file2}
    \end{tabularx}
\end{tcolorbox}

\begin{tcboxeditemize}[blankest, halign=center, valign=top, raster equal height=rows]{title=The captions are not aligned}
    \tcbitem \includegraphics{file1.png} 
    \tcbitem \includegraphics[scale=1.5]{file2.png}
    \tcbitem \captionof{figure}{file1} 
    \tcbitem \captionof{figure}{file2}
\end{tcboxeditemize}

\end{document}

在此处输入图片描述

相关内容