0

In the MWE below, the final box (on the right) is shifted down slightly compared to the other boxes.

How can I align boxes, text baselines, and the plus-signs nicely?

Here is the MWE:

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\tcbset{nobeforeafter,height=2cm,valign=bottom,box align=base}
\Large
\tcbox{a} + \tcbox{b} + \tcbox{x}=\tcbox{y}
\end{document}
  • That's the cause of the descender of y -- the base of the last box is lower than the base of the first three boxes – user31729 Jan 15 '18 at 12:29
1

This happens because y has a positive depth (like g, j, etc.). A solution is to raise the letter by its depth.

Here I define a \mytcbox that does this:

\newcommand{\mytcbox}[1]{%
\newbox\mytcBox%
\savebox{\mytcBox}{#1}%
\tcbox{\raisebox{\dp\mytcBox}{\usebox{\mytcBox}}}%
}

Here is an example:

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\tcbset{nobeforeafter,height=2cm,valign=bottom,box align=base}
\newcommand{\mytcbox}[1]{%
\newbox\mytcBox%
\savebox{\mytcBox}{#1}%
\tcbox{\raisebox{\dp\mytcBox}{\usebox{\mytcBox}}}%
}
\Large
\tcbox{a} + \tcbox{b} + \mytcbox{x} = \mytcbox{y} + \mytcbox{g} - \tcbox{g}
\end{document}

enter image description here

Note that for letter that have null depth the output is the same, and for the rest, the letter is raised by their depth.

  • this aligns the boxes, but not the text. I want the text and the boxes both aligned, I presume, by increasing the depth of the box. – Tim Jan 17 '18 at 11:27
0

This code seems to work, but it's not nice. It aligns both the box and the text, using the baseline. There's probably redundancy in it too.

\tcbset{on line,height=1cm,valign=bottom,box align=base,baseline=3mm}
\newcommand{\mybox}[1]{\tcbox{\raisebox{-2cm}[2cm][2cm]{#1}}}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.