1

In the following MWE, why is there an extra vertical space in Example 2 ?

\documentclass{article}

\usepackage[most]{tcolorbox}
\usepackage{showframe}
\usepackage{harmony}

\newtcolorbox{myFrame}
{colback = red, colframe = white, top = 0mm, bottom = 0mm, boxrule = 0pt, left = 2mm, right = 2mm}

\newcommand{\easy}{%
    \llap{\parbox[t][0pt]{1.7cm}{%
            \Acht{}test\\
            \small{}easy
    }}%
}
\newcommand{\easyBis}{%
    \llap{\parbox[t][0pt]{1.7cm}{%
            test\\
            \small{}easy
    }}%
}

\begin{document}
    
    \begin{myFrame}
        \easy
        Example 1\par
        This is the text of the exercise.\par
        By the way, I use tcolorbox to make my boxes.
    \end{myFrame}
    

    \begin{myFrame}
        \easyBis
        Example 2\par
        This is the text of the exercise.\par
        By the way, I use tcolorbox to make my boxes.
    \end{myFrame}
    
\end{document}

enter image description here

1 Answer 1

2

Don't use primitive tex boxes in vertical mode, they rarely do what you expect.

enter image description here

\documentclass{article}

\usepackage[most]{tcolorbox}
\usepackage{showframe}
\usepackage{harmony}

\newtcolorbox{myFrame}
{colback = red, colframe = white, top = 0mm, bottom = 0mm, boxrule = 0pt, left = 2mm, right = 2mm}

\newcommand{\easy}{%
    \leavevmode\llap{\parbox[t][0pt]{1.7cm}{%
            \leavevmode\Acht{}test\\
            \small{}easy
    }}%
}
\newcommand{\easyBis}{%
    \leavevmode\llap{\parbox[t][0pt]{1.7cm}{%
            test\\
            \small{}easy
    }}%
}

\begin{document}
    
    \begin{myFrame}
        \easy
        Example 1\par
        This is the text of the exercise.\par
        By the way, I use tcolorbox to make my boxes.
    \end{myFrame}
    

    \begin{myFrame}
        \easyBis
        Example 2\par
        This is the text of the exercise.\par
        By the way, I use tcolorbox to make my boxes.
    \end{myFrame}
    
\end{document}

or better, also hiding the height of note to get the same space above Example

enter image description here

\documentclass{article}

\usepackage[most]{tcolorbox}
\usepackage{showframe}
\usepackage{harmony}

\newtcolorbox{myFrame}
{colback = red, colframe = white, top = 0mm, bottom = 0mm, boxrule = 0pt, left = 2mm, right = 2mm}

\newcommand{\easy}{%
    \leavevmode\llap{\parbox[t][0pt]{1.7cm}{%
            \leavevmode\strut\smash{\Acht}test\\
            \small{}easy
    }}%
}
\newcommand{\easyBis}{%
    \leavevmode\strut\llap{\parbox[t][0pt]{1.7cm}{%
            test\\
            \small{}easy
    }}%
}

\begin{document}
    
    \begin{myFrame}
        \easy
        Example 1\par
        This is the text of the exercise.\par
        By the way, I use tcolorbox to make my boxes.
    \end{myFrame}
    

    \begin{myFrame}
        \easyBis
        Example 2\par
        This is the text of the exercise.\par
        By the way, I use tcolorbox to make my boxes.
    \end{myFrame}
    
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .