# fbox in tabular throws missing endgroup

I have to draw a border around my tables, so I'm using \fbox{} (is there a better way?). It works when using a threeparttable but with the normal tabular latex throws an error stating

Missing \endgroup inserted


I have closed the curly brackets. What am I missing? I've found the post booktabs and tiny horizontal space where it seems to work. See the code below:

\begin{table}[h]
\fbox{
\centering\caption{\textbf{blabla 1}}
\begin{tabular*}{0.9\columnwidth}{@{\extracolsep{\fill}}lc}
\toprule
\textbf{SF-36 Parameter} & \textbf{Mittelwert (SD)}\tabularnewline
\midrule
\midrule
Körperliche Funktionsfähigkeit & 56,5 (33,6)\tabularnewline
\midrule
Psychisches Wohlbefinden & 70,7 (17,8)\tabularnewline
\bottomrule
\end{tabular*}
}
\end{table}

-
You are trying to enclose the \caption within the \fbox. Is this what you're after? – Werner Dec 20 '11 at 19:20
Yes, indeed, that's what I want to do... – Jan Dec 20 '11 at 19:22
Possible duplicate: tex.stackexchange.com/questions/28412/…. See if the provided link helps you. It suggests using the float package and specifying the float style as boxed. If not, let us know. – Werner Dec 20 '11 at 19:25
I thought you wanted the caption above the table? That's how it is in your MWE. LaTeX considers figures and tables as floats, which it handles in a specific way. Apart from that, you can put a table in a figure environment and vice versa. It's just that the one is associated with the LoF and the other with the LoT. – Werner Dec 20 '11 at 19:40
\fbox works if you put it around a minipage. I would go with Mico's answer on @Werner's link – cmhughes Dec 20 '11 at 20:06

You can use the mdframed package to draw a box around the table:

\documentclass{article}
\usepackage{booktabs}
\usepackage[framemethod=tikz,xcolor=true]{mdframed}

\begin{document}
\begin{table}[h]
\begin{mdframed}[
tikzsetting={align=center,draw=red,ultra thick,align=center},
innerrightmargin=5pt,innerleftmargin=5pt,innerbottommargin=5pt
]
\begin{center}
\caption{\textbf{blabla 1}}
\begin{tabular*}{0.9\columnwidth}{@{\extracolsep{\fill}}lc}
\toprule
\textbf{SF-36 Parameter} & \textbf{Mittelwert (SD)}\tabularnewline
\midrule
\midrule
Körperliche Funktionsfähigkeit & 56,5 (33,6)\tabularnewline
\midrule
Psychisches Wohlbefinden & 70,7 (17,8)\tabularnewline
\bottomrule
\end{tabular*}
\end{center}
\end{mdframed}
\end{table}
\end{document}

-
In this case you should use \begin{center} instead of \centering – Marco Daniel Dec 20 '11 at 19:48
One last thing. When I use both mdframed and begin/end centering (see the code below), then the table is still not centered. \begin{table}[h] \begin{mdframed}[style=schwarzelinie] \begin{centering}\caption{blabla} \begin{tabular*}{0.9\columnwidth}{@{\extracolsep{\fill}}lc} \toprule SF-36 Parameter & Mittelwert (SD)\tabularnewline \midrule \midrule Körperliche Funktionsfähigkeit & 56,5 (33,6)\tabularnewline \end{tabular*}\end{centering} \end{mdframed} \end{table} See this image. – Jan Dec 20 '11 at 20:25
@MarcoDaniel: Thanks. Have added that and now the table is properly centered. – Peter Grill Dec 20 '11 at 20:40
@Jan: You need begin{center} instead of \begin{centering} – Marco Daniel Dec 20 '11 at 20:44

Perhaps you could define a new environment for your framed tables, like so (using fancybox):

\documentclass{article}

\usepackage{booktabs} % http://www.ctan.org/pkg/booktabs
\usepackage{caption}  % http://www.ctan.org/pkg/caption
\usepackage{fancybox} % http://www.ctan.org/pkg/fancybox

\newlength{\mylength}%
\setlength{\mylength}{\textwidth}%

\newenvironment{FramedTable}%
{\begin{table}[h]%
\begin{Sbox}%
\begin{minipage}{\mylength}%
\centering}%
{    \end{minipage}%
\end{Sbox}\fbox{\TheSbox}%
\end{table}}%

\begin{document}

\section*{Framed Tables!}

\begin{FramedTable}
\caption{Hello World}%
\begin{tabular}{@{}lll@{}}
\toprule
Apple & Banana & Cherry\\
\midrule
One & Two & Three\\
\bottomrule
\end{tabular}
\end{FramedTable}

\end{document}


This code yields:

-
Gorgeous. You can't use it in Lyx though. – Jan Dec 20 '11 at 19:50
Oh, I didn't realize you were using LyX. I've never used LyX, so I'm unfamiliar with what works and what doesn't work. Perhaps then you should consider Peter Grill's answer. mdframed is a great and easy to use package. :) – user2473 Dec 20 '11 at 20:00
Lyx gives some nasty graphical security ;-) I am indeed using Peter's answer but defining a new environment looked very impressive. – Jan Dec 20 '11 at 20:03

\fbox{..} enforces restricted horizontal mode on its content, i.e. you can't have paragraphs in them, except if you add a \parbox or minipage yourself. You need to use a framing environment which allows vertical mode inside it.

Besides the mentioned mdframed there is also the adjustbox environment from the package with the same name, if used with the minipage and fbox option.

You should also reverse the skip above and below the \caption because by default it is designed to go below things, so \belowcaptionskip is normally empty.

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\begin{table}[h]
\centering
\belowcaptionskip\abovecaptionskip
\abovecaptionskip=0pt
\caption{\textbf{blabla 1}}
\begin{tabular*}{0.9\columnwidth}{@{\extracolsep{\fill}}lc}
\toprule
\textbf{SF-36 Parameter} & \textbf{Mittelwert (SD)}\tabularnewline
\midrule
\midrule
Körperliche Funktionsfähigkeit & 56,5 (33,6)\tabularnewline
\midrule
Psychisches Wohlbefinden & 70,7 (17,8)\tabularnewline
\bottomrule
\end{tabular*}