Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
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
2  
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
1  
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
1  
\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

3 Answers 3

up vote 7 down vote accepted

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

enter image description here

\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}
share|improve this answer
1  
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
1  
@MarcoDaniel: Thanks. Have added that and now the table is properly centered. –  Peter Grill Dec 20 '11 at 20:40
1  
@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}%
\addtolength{\mylength}{-2\fboxsep}%
\addtolength{\mylength}{-2\fboxrule}%

\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:

MWE solution for OP's question

share|improve this answer
    
Gorgeous. You can't use it in Lyx though. –  Jan Dec 20 '11 at 19:50
1  
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}
\usepackage{adjustbox}

\begin{document}
\begin{table}[h]
\begin{adjustbox}{minipage=\linewidth-2\fboxsep-2\fboxrule,fbox}
\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*}
\end{adjustbox}
\end{table}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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