3

I want to use tcolorbox to create on line (inline) boxes of equal height, using equal height group. But the boxes are positioned at different heights.

MWE:

\documentclass[a4paper, oneside, 12pt, parskip=half]{scrartcl}

\usepackage[many]{tcolorbox}
\tcbset{common/.style={
    enhanced, size=small, nobeforeafter, on line, drop fuzzy shadow
  }
}
\newtcbox{\databoxcenter}[1]{
  common, leftrule=0pt, rightrule=0pt, equal height group=#1
}
\newtcbox{\databoxleft}[1]{
  common, rightrule=0pt, equal height group=#1
}
\newtcbox{\databoxright}[1]{
  common, leftrule=0pt, equal height group=#1
}

\begin{document}

The following boxes are positioned as if \texttt{equal height group} is not in effect:

\databoxleft{addr}{2/17,} \databoxcenter{addr}{Hamlet 5,} \databoxright{addr}{China}. The heights do seem equal, though.

\end{document}
2

One possible way is to adjust the baseline value, i.e. baseline=2mm seems to be an appropriate value.

\documentclass[a4paper, oneside, 12pt, parskip=half]{scrartcl}


\usepackage[many]{tcolorbox}
\tcbset{common/.style={
    box align=base,
    enhanced jigsaw, size=small,on line,baseline=2mm,drop fuzzy shadow
  }
}
\newtcbox{\databoxcenter}[1]{
  common,leftrule=0pt, rightrule=0pt, equal height group=#1
}

\newtcbox{\databoxleft}[1]{
  common, rightrule=0pt, equal height group=#1
}

\newtcbox{\databoxright}[1]{
  common, leftrule=0pt, equal height group=#1
}

\begin{document}

The following boxes are positioned as if \texttt{equal height group} is not in effect:

\databoxleft{addr}{2/17,} \databoxcenter{addr}{Hamlet,5} \databoxright{addr}{China}. The heights do seem equal, though.

\end{document}
  • Fantastic, simple. Tells me I should respect the world of typesetting as a formal domain, which is nothing less than the world of front-end programming (am a programmer). I feel your vibe; I use Emacs too! – user152148 Feb 8 '18 at 10:29
  • @JonWong: Using a computer for typesetting it is programming in the long end... either by using the knowledge of others are applying own ideas... – user31729 Feb 8 '18 at 21:51
2

Another solution could be to force equal height and depth for all boxes. I've done adding before upper=\strut in common style definition.

\documentclass[a4paper, oneside, 12pt, parskip=half]{scrartcl}

\usepackage[many]{tcolorbox}
\tcbset{common/.style={
    enhanced, size=small, nobeforeafter, on line, drop fuzzy shadow,
    before upper=\strut
  }
}
\newtcbox{\databoxcenter}[1]{
  common, leftrule=0pt, rightrule=0pt, equal height group=#1
}
\newtcbox{\databoxleft}[1]{
  common, rightrule=0pt, equal height group=#1
}
\newtcbox{\databoxright}[1]{
  common, leftrule=0pt, equal height group=#1
}

\begin{document}

The following boxes are positioned as if \texttt{equal height group} is not in effect:

\databoxleft{addr}{2/17,} \databoxcenter{addr}{Hamlet 5,} \databoxright{addr}{China}. The heights do seem equal, though.

\end{document}

enter image description here

  • @lgnasi Nice solution. Similar to tex.stackexchange.com/questions/290321/… , which I also used as a hack before I found the answer to this question. But it defeats my option size=small. – user152148 Feb 8 '18 at 10:26
  • @JonWong To compensate box size increase due to \strut, you can add boxsep=0pt after size=small. – Ignasi Feb 8 '18 at 10:50

Your Answer

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