15

Is it possible to create a table inside a table like this in LaTeX, can someone please lead me in right direction to achieve this? Thanks

enter image description here

4
  • yes tabular environments can be nested, a tabular can be used wherever you may have text. Did you try? if you want help with a specific aspect or error ask about that Commented May 14, 2014 at 0:16
  • Nice, but it dosent seem like i can nest tabularx tables, I need it to break lines since my table contains some long lines.
    – user265767
    Commented May 14, 2014 at 0:36
  • I think you might find this post useful: [How to Nest Tables][1] [1]: tex.stackexchange.com/questions/7958/how-to-nest-tables Commented May 14, 2014 at 0:36
  • you can nest tabularx (see the package documentation) but you don't need tabularx to get line breaking, just a normal tabular p column Commented May 14, 2014 at 0:38

2 Answers 2

16

Here's one possibility nesting tabulars:

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{array}
\usepackage[table]{xcolor}

\begin{document}

\begingroup
\renewcommand\arraystretch{1.3}
\noindent\begin{tabular}{
  | >{\ttfamily\raggedright}p{2cm}
  | >{\sffamily\raggedright}p{2.5cm}
  | >{\sffamily}p{\dimexpr\textwidth-6\tabcolsep-4\fboxsep-4.5cm\relax} |
}
\hline
\rowcolor{gray!20}\multicolumn{1}{|l|}{\bfseries\sffamily Name} 
  & \multicolumn{1}{l|}{\bfseries\sffamily Type} 
  & \multicolumn{1}{l|}{\bfseries\sffamily Description} \\
\hline
& & \\[-2ex]
d\_super & struct disk\_superblock &
  \begin{tabular}[t]{
    | >{\ttfamily\raggedright}p{1.5cm}
    | >{\sffamily\raggedright}p{1.5cm}
    | >{\sffamily}p{\dimexpr\textwidth-12\tabcolsep-5\fboxsep-7.5cm\relax} |
  }
  \firsthline
  \multicolumn{1}{|l|}{\cellcolor{gray!20}\bfseries Name} 
    & \multicolumn{1}{l|}{\cellcolor{gray!20}\bfseries Type} 
    & \multicolumn{1}{l|}{\cellcolor{gray!20}\bfseries Description} \\
  \hline
  magic & char array & magic number used to indicate if file system is generated by our OS \\
  \hline
  magic & char array & magic number used to indicate if file system is generated by our OS \\
  \hline
  \end{tabular} \\[15ex]
\hline
ibmap & void\textsuperscript{*} & Pointer to l-Nodes bitmap \\
\hline
ibmap & void\textsuperscript{*} & Pointer to l-Nodes bitmap \\
\hline
ibmap & void\textsuperscript{*} & Pointer to l-Nodes bitmap \\
\hline
\end{tabular}
\endgroup

\end{document}

enter image description here

And suppressing the vertical rules and using booktabs:

\documentclass{article}
\usepackage[margin=3cm]{geometry}
\usepackage{array}
\usepackage{booktabs}
\usepackage[table]{xcolor}

\begin{document}

\noindent\begin{tabular}{
   >{\ttfamily\raggedright}p{2cm}
   >{\sffamily\raggedright}p{2.5cm}
   >{\sffamily}p{\dimexpr\textwidth-6\tabcolsep-4\fboxsep-4.5cm\relax}
}
\toprule
\multicolumn{1}{l}{\bfseries\sffamily Name} 
  & \multicolumn{1}{l}{\bfseries\sffamily Type} 
  & \multicolumn{1}{l}{\bfseries\sffamily Description} \\
\midrule
& & \\[-2ex]
d\_super & struct disk\_superblock &
  \vspace{-15pt}\begin{tabular}[t]{
     >{\ttfamily\raggedright}p{1.5cm}
     >{\sffamily\raggedright}p{1.5cm}
     >{\sffamily}p{\dimexpr\textwidth-12\tabcolsep-5\fboxsep-7.5cm\relax}
  }
  \toprule
  \multicolumn{1}{l}{\bfseries\sffamily Name} 
    & \multicolumn{1}{l}{\bfseries\sffamily Type} 
    & \multicolumn{1}{l}{\bfseries\sffamily Description} \\
  \midrule
  d\_super & char array & magic number used to indicate if file system is generated by our OS \\
  magic & char array & magic number used to indicate if file system is generated by our OS \\
  \bottomrule
  \end{tabular} \\[16.5ex]
\midrule  
ibmap & void\textsuperscript{*} & Pointer to l-Nodes bitmap \\
ibmap & void\textsuperscript{*} & Pointer to l-Nodes bitmap \\
ibmap & void\textsuperscript{*} & Pointer to l-Nodes bitmap \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

5

You can nest tabularx without problems. I've done this to create a RPG character sheet, with lots of little details added with the help of the good people here on tex.SE... ripping some of the source from the document for example, translating and commenting for easier reading... the screenshot is the original German though. And I don't have a stand-alone, compilable example right now, this is part of a >500 page volume, the preamble alone coming in at 12k...

The original

% In the preamble... you *probably* need some packages in addition to
% tabularx for the below to work, but it's inconsequential to the subject
% of tabularx nesting, and I don't have the leisure to turn this into
% a compilable stand-alone

\newcommand{\Top}{\rule{0pt}{2.6ex}}       % strut for \hline above
\newcommand{\Bot}{\rule[-1.2ex]{0pt}{0pt}} % strut for \hline below

% Create an underline as long as the given text would be
\newcommand*{\srule}[2][0pt]{\setbox0\hbox{#2}\rule[#1]{\wd0}{0.4pt}}

% New tabularx column type: C is like X, just centered.
\newcolumntype{C}{>{\centering\arraybackslash}X}

% Making \cellwidth the width of the tabularx cell we are currently in
\makeatletter
\newcommand{\cellwidth}{\TX@col@width}
\makeatother

% --------------------------------------
% In the document...
% --------------------------------------

% Full-width table with three cells, each containing a table in turn
% @{} suppressing padding -- the sub-tables take care of that.
\noindent\begin{tabularx}{\textwidth}{@{}X@{}X@{}X@{}}
{
% Cell 1 -- Character description
\begin{tabularx}{\cellwidth}{|lX}
\hline
\multicolumn{2}{|c}{\scshape\textbf{Character}\Top{}\Bot{}}\\
\textbf{Name:}        & \hrulefill\Top{}\\
\textbf{Race:}        & \hrulefill\\
\textbf{Height:}      & \hrulefill\\
\textbf{Build:}       & \hrulefill\\
\textbf{Hair:}        & \hrulefill\\
\textbf{Eyes:}        & \hrulefill\\
\textbf{Outlook:}     & \hrulefill\\
\textbf{Age:}         & \hrulefill\Bot{}\\
\hline
\end{tabularx}
} & {
% Cell 2 -- Header, Basic stats.
\begin{tabularx}{\cellwidth}{@{}C@{}}
{
% Actually setting up a sub-sub-table here for the header...
\begin{tabularx}{\cellwidth}{|@{}C@{}|}
\hline
% Inserting a graphical header here, fudging a bit with \rule to get the padding right
\rule{0pt}{29.25pt}\includegraphics[width=0.95\cellwidth]{pic/CharacterSheet.pdf}\\
\scshape\textbf{Player}\\
\Top{}\Bot{}\\
\hline
\end{tabularx}
}\\
{
% ...and another sub-sub-table for the basic stats.
\begin{tabularx}{\cellwidth}{lX}
\textbf{Profession:}   & \hrulefill\Top{}\\
\textbf{Power Realm:}  & \hrulefill\\
\textbf{Experience:}   & \hrulefill\\
\textbf{Level:}        & \hrulefill\Bot{}\\
\hline
\end{tabularx}}\\
\end{tabularx}
} & {
% Cell 3 -- Languages
\begin{tabularx}{\cellwidth}{|Xcc|}
\hline
\multicolumn{3}{|c|}{\scshape\textbf{Languages}}\Top{}\Bot{}\\
\textbf{Language} & \textbf{Spoken} & \textbf{Written}\Top{}\\
\hrulefill       & \srule{Spoken}  & \srule{Written}\\
\hrulefill       & \srule{Spoken}  & \srule{Written}\\
\hrulefill       & \srule{Spoken}  & \srule{Written}\\
\hrulefill       & \srule{Spoken}  & \srule{Written}\\
\hrulefill       & \srule{Spoken}  & \srule{Written}\\
\hrulefill       & \srule{Spoken}  & \srule{Written}\\
\hrulefill       & \srule{Spoken}  & \srule{Written}\Bot{}\\
\hline
\end{tabularx}
}\\  
\end{tabularx}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .