1

I want to set the boxrule of a tcolorbox, but when I add a tabularx to it, it is suddenly ignored.

box widths of tcolorboxes

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{colortbl}

\begin{document}

\begin{tcolorbox}[boxrule=5pt,tabularx={l}]
hello world
\end{tcolorbox}

\begin{tcolorbox}[boxrule=5pt]
hello world
\end{tcolorbox}

\end{document}

How do I enforce the boxrule?

What I want to do is force the frame width to match \hline.

  • I am running tcolorbox v4.20. – bitmask Sep 18 '19 at 15:47
  • 1
    Change the order of the pgf keys: \begin{tcolorbox}[tabularx={l},boxrule=5pt] hello world \end{tcolorbox}. That is, boxrule=5pt needs to go after tabularx={l}. – user194703 Sep 18 '19 at 15:48
  • Oh, this is just evil! I've been at it for over half an hour. Works. – bitmask Sep 18 '19 at 15:50
  • 1
    Being a cat helps. ;-) – user194703 Sep 18 '19 at 15:50
  • If you want the rep, feel free to turn the comment into an answer. – bitmask Sep 18 '19 at 15:52
2

pgf keys are "only" some cleverly packaged macros. Therefore the order in which you use them matters, simply because the order in which you execute macros matters, too. So you may want to put the key that sets the line width "as late as possible". In your case, there are only two keys so you may want to put boxrule=5pt last.

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{tabularx}
\usepackage{colortbl}

\begin{document}

\begin{tcolorbox}[boxrule=5pt,tabularx={l}]
hello world
\end{tcolorbox}

\begin{tcolorbox}[tabularx={l},boxrule=5pt]
hello world
\end{tcolorbox}

\begin{tcolorbox}[boxrule=5pt]
hello world
\end{tcolorbox}

\end{document}

enter image description here

| improve this answer | |

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.