´╗┐ Chapter 5, Creating Tables and Inserting Pictures | TeXblog

Chapter 5, Creating Tables and Inserting Pictures

Contents:


Lining up information using the tabbing environment

\documentclass{article}
\begin{document}
\begin{tabbing}
\emph{Info:} \= Software \= : \= \LaTeX \\
  \> Author \> : \> Leslie Lamport \\
  \> Website \> : \> www.latex-project.org
\end{tabbing}
\end{document}
tabbing example
\documentclass{article}
\newcommand{\head}[1]{\textbf{#1}}
\begin{document}
\begin{tabbing}
\head{Type} \= \head{Command} \= \head{Declaration} \=
  \head{Example}\\
Family \> \verb|\textrm{...}| \> \verb|\rmfamily|
    \> \rmfamily Example text\\
\end{tabbing}
\end{document}

Not good yet:

tabular example
\documentclass{article}
\newcommand{\head}[1]{\textbf{#1}}
\begin{document}
\begin{tabbing}
Family \= \verb|\textrm{...}| \= \head{Declaration} \= \kill\\
  \> \head{Command} \> \head{Declaration} \> \head{Example}\\
Family \> \verb|\textrm{...}| \> \verb|\rmfamily| \> \rmfamily
    Example text\\
  \> \verb|\textsf{...}| \> \verb|\sffamily| \> \sffamily
    Example text\\
  \> \verb|\texttt{...}| \> \verb|\ttfamily| \> \ttfamily
    Example text
\end{tabbing}
\end{document}
tabular example

Creating tables

\documentclass{article}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\begin{document}
\begin{tabular}{ccc}
  \hline
  \head{Command} & \head{Declaration} & \head{Output}\\
  \hline
  \verb|\textrm| & \verb|\rmfamily| & \rmfamily Example text\\
  \verb|\textsf| & \verb|\sffamily| & \sffamily Example text\\
  \verb|\texttt| &\verb|\ttfamily| & \ttfamily Example text\\
  \hline
\end{tabular}
\end{document}
tabular example

Horizontal alignment within cells:

\documentclass{article}
\begin{document}
\begin{tabular}{|l|c|r|p{1.7cm}|}
  \hline
  left & centered & right & a fully justified paragraph cell\\
  \hline
  l & c & r & p\\
  \hline
\end{tabular}
\end{document}
tabular example

Note: vertical lines are just for checking the alignment – generally they are not recommendable.

Vertical alignment within cells:

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{@{}lp{1.2cm}m{1.2cm}b{1.2cm}@{}}
  \hline
  baseline & aligned at the top& aligned at the middle
    & aligned at the bottom\\
  \hline
\end{tabular}
\end{document}
tabular example
\documentclass{article}
\usepackage{array}
\setlength{\extrarowheight}{4pt}
\begin{document}
\begin{tabular}{@{}>{\itshape}ll!{:}l<{.}@{}}
  \hline
  Info: & Software & \LaTeX\\
  & Author & Leslie Lamport\\
  & Website & www.latex-project.org\\
\hline
\end{tabular}
\end{document}
tabular example

Nice rules with booktabs:

\documentclass{article}
\usepackage{booktabs}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\begin{document}
\begin{tabular}{ccc}
  \toprule[1.5pt]
  \head{Command} & \head{Declaration} & \head{Output}\\
  \midrule
  \verb|\textrm| & \verb|\rmfamily| & \rmfamily Example text\\
  \verb|\textsf| & \verb|\sffamily| & \sffamily Example text\\
  \verb|\texttt| &\verb|\ttfamily| & \ttfamily Example text\\
  \bottomrule[1.5pt]
\end{tabular}
\end{document}
tabular example

Merging cells horizontally:

\documentclass{article}
\usepackage{booktabs}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\begin{document}
\begin{tabular}{@{}*3l@{}}
  \toprule[1.5pt]
  \multicolumn{2}{c}{\head{Input}} &
    \multicolumn{1}{c}{\head{Output}}\\
  \head{Command} & \head{Declaration} & \\
  \cmidrule(r){1-2}\cmidrule(l){3-3}
  \verb|\textrm| & \verb|\rmfamily| & \rmfamily Example text\\
  \verb|\textsf| & \verb|\sffamily| & \sffamily Example text\\
  \verb|\texttt| & \verb|\ttfamily| & \ttfamily Example text\\
  \bottomrule[1.5pt]
\end{tabular}
\end{document}
tabular example
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\begin{document}
\begin{tabular}{@{}l*2{>{\textbackslash\ttfamily}l}%
  l<{Example text}@{}}
  \toprule[1.5pt]
  & \multicolumn{2}{c}{\head{Input}} &
    \multicolumn{1}{c}{\head{Output}}\\
  & \normal{\head{Command}} &
  \normal{\head{Declaration}} & \normal{}\\
  \cmidrule(lr){2-3}\cmidrule(l){4-4}
  Family &  textrm & rmfamily & \rmfamily\\
  & textsf & sffamily & \sffamily\\
  & texttt & ttfamily & \ttfamily\\
  \bottomrule[1.5pt]
\end{tabular}
\end{document}
tabular example

Merging cells vertically:

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\begin{document}
\begin{tabular}{@{}l*2{>{\textbackslash\ttfamily}l}%
  l<{Example text}@{}}
  \toprule[1.5pt]
  & \multicolumn{2}{c}{\head{Input}} &
    \multicolumn{1}{c}{\head{Output}}\\
  & \normal{\head{Command}} &
  \normal{\head{Declaration}} & \normal{}\\
  \cmidrule(lr){2-3}\cmidrule(l){4-4}
  \multirow{3}{*}{Family} &  textrm & rmfamily & \rmfamily\\
  & textsf & sffamily & \sffamily\\
  & texttt & ttfamily & \ttfamily\\
  \bottomrule[1.5pt]
\end{tabular}
\end{document}
tabular example
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand{\head}[1]{\textnormal{\textbf{#1}}}
\newcommand{\normal}[1]{\multicolumn{1}{l}{#1}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{@{}l*2{>{\textbackslash\ttfamily}l}%
  l<{Example text}l@{}}
\toprule[1.5pt]
  & \multicolumn{2}{c}{\head{Input}}
  & \multicolumn{2}{c}{\head{Output}}\\
  & \normal{\head{Command}} & \normal{\head{Declaration}}
  & \normal{\head{Single use}} & \head{Combined}\\
  \cmidrule(lr){2-3}\cmidrule(l){4-5}
  \multirow{3}{*}{Family} &  textrm & rmfamily & \rmfamily & \\
  & textsf & sffamily & \sffamily & \\
  & texttt & ttfamily & \ttfamily & \\
  \cmidrule(lr){2-3}\cmidrule(lr){4-4}
  \multirow{2}{1.1cm}{Weight} & textbf & bfseries & \bfseries
  & \multirow{2}{1.8cm}{\sffamily\bfseries Bold and sans-serif} \\
        & textmd & mdseries & \mdseries & \\
\cmidrule(lr){2-3}\cmidrule(lr){4-4}
\multirow{4}{*}{Shape} & textit & itshape & \itshape & \\
        & textsl & slshape & \slshape &
  \multirow{2}{1.8cm}{\sffamily\slshape Slanted and sans-serif}\\
        & textsc & scshape & \scshape & \\
        & textup & upshape & \upshape & \\
\cmidrule(lr){2-3}\cmidrule(lr){4-4}
Default & textnormal & normalfont & \normalfont & \\
\bottomrule[1.5pt]
\end{tabular}
\caption{\LaTeX\ font selection}
\end{table}
\end{document}
tabular example

Back to the list of contents

One Comment

  1. In the table “Merging cells horizontally :”
    I wanted to make a 10 column table, if I use 10 instead of 3 in the following command it gives error
    \begin{tabular}{@{}*3l@{}}

    please help .

Leave a Reply to Surya K. Ghosh Cancel reply

Required fields are marked *