Tcolorbox Alignment – Solving Sidebyside Alignment Problem in Tcolorbox in LaTeX

tcolorbox

My aim is to make some sort of solutions to exercises. I have got some idea on using tcolorbox stuff, but this alignment issue seems pretty weird.

Here is what I have right now.
enter image description here

What I want is, since 1.13 is some sort of problem index, It should go on top. I tried using sidebyside align=top but it doesn't work. How can I fix this issue?

The following is LaTeX code to reproduce above image.

\documentclass[a4paper, 10pt]{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\usepackage{tikz}
\usepackage{tikzpagenodes}

\parindent=0pt

\usepackage{xparse}
\begin{document}
    \begin{tcolorbox}[sidebyside,sidebyside align=top,lefthand width=1.5cm]
        \begin{tcolorbox}[width=\textwidth,before skip=0pt,boxsep=0pt,left=0pt,right=0pt,top=0pt,bottom=0pt]
            {\sffamily \bfseries {\color{purple}\S 1.13}}
        \end{tcolorbox}
    \tcblower
        \begin{tcolorbox}[width=\textwidth,before skip=0pt,boxsep=0pt,left=0pt,right=0pt,top=0pt,bottom=0pt]
            \lipsum[1]
        \end{tcolorbox}
    \end{tcolorbox}
\end{document}

Any ideas to fix the issues?

Thanks for reading.

Best Answer

side by side alignment options include top seam which do what you want as it's shown in following first example.

Your example shows nested tcolorboxes. This means that the boxes are not breakable. If this is your intention, I've nothing to say. But, in any case, I propose a similar format, without the external box, which allows breakable boxes and an automatic counter for the boxes.

\documentclass[a4paper, 10pt]{article}
\usepackage{lipsum}
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\usepackage{tikz}
\usepackage{tikzpagenodes}

\parindent=0pt

\newtcolorbox[auto counter, number within=section]{problem}[1][]{enhanced, attach boxed title to top left={yshift=-\tcboxedtitleheight, xshift=-2cm}, left skip=2cm,
    colbacktitle=tcbcolback, coltitle=purple, fonttitle=\sffamily\bfseries,
    boxed title size=title,
    boxed title style={text width=1.8cm},
    title={\S \thetcbcounter},#1
}


\usepackage{xparse}
\begin{document}
    \begin{tcolorbox}[sidebyside,sidebyside align=top seam,lefthand width=1.5cm]
        \begin{tcolorbox}[width=\textwidth,before skip=0pt,boxsep=0pt,left=0pt,right=0pt,top=0pt,bottom=0pt]
            {\sffamily \bfseries {\color{purple}\S 1.13}}
        \end{tcolorbox}
    \tcblower
        \begin{tcolorbox}[width=\textwidth,before skip=0pt,boxsep=0pt,left=0pt,right=0pt,top=0pt,bottom=0pt]
            \lipsum[1]
        \end{tcolorbox}
    \end{tcolorbox}
    
    \begin{problem}
    \lipsum[1]
    \end{problem}
\end{document}

enter image description here

Related Question