1

I try to use colored framed boxes inside tabular environments. Is it possible to used "mdframed" environment for it?

Unfortunately, the code below does not work (it gives: «! LaTeX Error: Something's wrong--perhaps a missing \item.»)

\documentclass{article}
\usepackage[english]{babel}
\usepackage{mdframed}
\begin{document}
\begin{tabular}{ | l |}
22222

\begin{mdframed}
1111
\end{mdframed}
\end{tabular}
\end{document}

Is there any magic to do it (or may be there exists another colored frame boxes package, compatible with tabular/tabulary/ environment)?

Update: Actually, I work with ReStructedText → (Sphinx) → Latex → (xelatex) → PDF generation, and have low options to customize generated latex code. I use some mdframed environment for notes/warnings/admonitions, because they frequently breaks between pages, and mdframed looks best options for it. But small notes, should be OK inside tables, so I trying to make universal environment, that works within and without tables.

Update2: I solved my problem by monkey-patching latex tables generation by sphinx, but still interested if any solution exists to put framed box inside "tabular" without specifying fixed "parbox" width for columns.

  • Try to change |l| to |p{10cm}|, if the | are really needed – user31729 Jul 14 '16 at 16:02
2

Replace the l column type with a p (parbox) type, however, the width must be specified too.

Make sure to use sufficient zoom-factor for the viewer, as the lines tend to be not displayed.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{mdframed}
\usepackage{tcolorbox}
\begin{document}
\begin{tabular}{ | p{10cm} |}
\begin{mdframed}
1111
\end{mdframed} \\
\begin{tcolorbox}
1111
\end{tcolorbox}
\end{tabular}

\end{document}
  • Thank you very much! If I specify column width or wrap "mdframed" inside minipage with given width, all OK. But unfortunately I cannot specify column width for tabular (latex code automatically generated from ReStructuredText by Sphinx, and Sphinx entrust Latex to find optimal column widths basing on table content). – Stas Fomin Jul 14 '16 at 17:12
  • @StasFomin: I'll try to find another way – user31729 Jul 14 '16 at 21:17
  • I solved my problem by monkey-patching latex tables generation by sphinxdoc, but still interested if any solution exists to put framed box inside "tabular" without specifing fixed width for columns. Thank you again! – Stas Fomin Jul 15 '16 at 12:33

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.