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 am working on report format using mdframed and I need to add table inside mdframed.

\documentclass[11pt]{article}
\usepackage[table]{xcolor}
\usepackage{array,ragged2e}
\usepackage[pdftex]{graphicx}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage[margin=1cm]{geometry}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.9}
\begin{document}
\begin{mdframed}[roundcorner=10pt,leftmargin=1, rightmargin=1, linecolor=orange,outerlinewidth=1, innerleftmargin=15, innertopmargin=15,innerbottommargin=15]
\textbf{Detailed Genotype Table}
\leavevmode
\newline
\begin{table}[ht]
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
\begin{center}
\rowcolors{1}{}{lightgray}
\begin{tabular}{|{\rule{0pt}{2cm}}c |P{2cm} | P{2cm} | P{2cm}|P{2cm} | P{2cm} | P{2cm}|P{2cm} | P{2cm} | P{2cm}|}
 \rowcolor{orange} Gene &SNP &Odds Ratio &Genotype &Genotype &Genotypic Effect &Citations &Frequency\\                              
  \hline
  1 & 2.36 & 1.08 & -0.49 & -0.82 & -0.65 \\
  2 & -0.68 & -1.13 & -0.42 & -0.72 & 1.51 \\
  3 & -1.00 & 0.02 & -0.54 & 0.31 & 1.28 \\
  4 & -0.99 & -0.54 & 0.97 & -1.12 & 0.59 \\
  5 & -2.35 & -0.29 & -0.53 & 0.30 & -0.30 \\
  6 & -0.10 & 0.06 & -0.85 & 0.10 & -0.60 \\
  \hline
\end{tabular}
\end{center}
\end{table}
\leavevmode
\newline
\end{mdframed}
\leavevmode
\newline
\end{document}

But in the above code i am not able to get table inside mdframed. May i know where i am wrong. Any example will help me a lot.

Thanks

share|improve this question
2  
You can't put the frame around a floating object (the {table}) You can probably put it around the {tabular}+caption I would guess. –  Alan Munn Apr 3 '12 at 2:03
add comment

1 Answer

up vote 7 down vote accepted

Do not use the floating environment table inside mdframed; it doesn't make much sense to try to frame a floating object:

\documentclass[11pt]{article}
\usepackage[table]{xcolor}
\usepackage{array,ragged2e}
\usepackage[pdftex]{graphicx}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage[margin=1cm]{geometry}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.9}

\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}

\begin{document}

\begin{mdframed}[roundcorner=10pt,leftmargin=1, rightmargin=1, linecolor=orange,outerlinewidth=1, innerleftmargin=15, innertopmargin=15,innerbottommargin=15]

\textbf{Detailed Genotype Table}

\centering
\rowcolors{1}{}{lightgray}
\begin{tabular}{|>{\rule{0pt}{2cm}}c |P{2cm} | P{2cm} | P{2cm}|P{2cm} | P{2cm} | P{2cm}|P{2cm} | P{2cm} | P{2cm}|}
 \rowcolor{orange} Gene &SNP &Odds Ratio &Genotype &Genotype &Genotypic Effect &Citations &Frequency\\                              
  \hline
  1 & 2.36 & 1.08 & -0.49 & -0.82 & -0.65 \\
  2 & -0.68 & -1.13 & -0.42 & -0.72 & 1.51 \\
  3 & -1.00 & 0.02 & -0.54 & 0.31 & 1.28 \\
  4 & -0.99 & -0.54 & 0.97 & -1.12 & 0.59 \\
  5 & -2.35 & -0.29 & -0.53 & 0.30 & -0.30 \\
  6 & -0.10 & 0.06 & -0.85 & 0.10 & -0.60 \\
  \hline
\end{tabular}
\end{mdframed}

\end{document}

enter image description here

If, however, you need the object to float, then you can invert the nesting order:

\documentclass[11pt]{article}
\usepackage[table]{xcolor}
\usepackage{array,ragged2e}
\usepackage[pdftex]{graphicx}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage[margin=1cm]{geometry}
\usepackage[table]{xcolor}
\definecolor{lightgray}{gray}{0.9}

\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}

\begin{document}

\begin{table}
\begin{mdframed}[roundcorner=10pt,leftmargin=1, rightmargin=1, linecolor=orange,outerlinewidth=1, innerleftmargin=15, innertopmargin=15,innerbottommargin=15]
\centering
\textbf{Detailed Genotype Table}

\rowcolors{1}{}{lightgray}
\begin{tabular}{|>{\rule{0pt}{2cm}}c |P{2cm} | P{2cm} | P{2cm}|P{2cm} | P{2cm} | P{2cm}|P{2cm} | P{2cm} | P{2cm}|}
 \rowcolor{orange} Gene &SNP &Odds Ratio &Genotype &Genotype &Genotypic Effect &Citations &Frequency\\                              
  \hline
  1 & 2.36 & 1.08 & -0.49 & -0.82 & -0.65 \\
  2 & -0.68 & -1.13 & -0.42 & -0.72 & 1.51 \\
  3 & -1.00 & 0.02 & -0.54 & 0.31 & 1.28 \\
  4 & -0.99 & -0.54 & 0.97 & -1.12 & 0.59 \\
  5 & -2.35 & -0.29 & -0.53 & 0.30 & -0.30 \\
  6 & -0.10 & 0.06 & -0.85 & 0.10 & -0.60 \\
  \hline
\end{tabular}
\end{mdframed}
\end{table}

\end{document}
share|improve this answer
add comment

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.