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

Colas
  • 6,772
  • 4
  • 46
  • 96

1 Answers1

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}

David Carlisle
  • 757,742