5

I'm new with LaTeX. So, I'm supposed to create a table and this is the code:

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{graphicx}

\begin{table}[]
\centering
\resizebox{\textwidth}{!}{%
\begin{tabular}{@{}|c|l|c|@{}}
\toprule
\multicolumn{2}{|c|}{\textbf{Cortex A9 Parameters}}               &     \textbf{Values} \\ \midrule
\multicolumn{2}{|c|}{\textbf{Core clock}}                         & 800 MHz         \\ \midrule
\multirow{5}{*}{\textbf{L2}}           & \textbf{Size}            & 512 kB          \\ \cmidrule(l){2-3} 
                                   & \textbf{Associativity}   & 8               \\ \cmidrule(l){2-3} 
                                   & \textbf{Latency}         & 8               \\ \cmidrule(l){2-3} 
                                   & \textbf{MSHRs}           & 11              \\ \cmidrule(l){2-3} 
                                   & \textbf{Write buffers}   & 9               \\ \midrule
 \multirow{4}{*}{\textbf{L1 - I}}       & \textbf{Size}            & 32 kB           \\ \cmidrule(l){2-3} 
                                   & \textbf{Associativity}   & 4               \\ \cmidrule(l){2-3} 
                                   & \textbf{Latency}         & 1               \\ \cmidrule(l){2-3} 
                                   & \textbf{MSHRs}           & 2               \\ \midrule
 \multirow{5}{*}{\textbf{L1 - D}}       & \textbf{Size}            & 32 kB           \\ \cmidrule(l){2-3} 
                                   & \textbf{Associativity}   & 4               \\ \cmidrule(l){2-3} 
                                   & \textbf{Latency}         & 1               \\ \cmidrule(l){2-3} 
                                   & \textbf{MSHRs}           & 4               \\ \cmidrule(l){2-3} 
                                   & \textbf{Write buffers}   & 16              \\ \midrule
 \textbf{Stride prefetcher}             & \textbf{Degree}          & 1               \\ \midrule
 \multirow{2}{*}{\textbf{Global BP}}    & \textbf{Entries}         & 4096            \\ \cmidrule(l){2-3} 
                                   & \textbf{Bits}            & 2               \\ \midrule
 \multicolumn{2}{|c|}{\textbf{BTB entries}}                        & 4096            \\ \midrule
 \multicolumn{2}{|c|}{\textbf{Return Address Stack (RAS) entries}} & 8               \\ \midrule
 \multicolumn{2}{|c|}{\textbf{Issues width}}                       & 2               \\ \midrule
 \multicolumn{2}{|c|}{\textbf{Pipeline stages}}                    & 8               \\ \midrule
 \multicolumn{2}{|c|}{\textbf{Physical INT registers}}             & 62              \\ \midrule
 \multicolumn{2}{|c|}{\textbf{Physical FP registers}}              & 256             \\ \midrule
 \multicolumn{2}{|c|}{\textbf{IQ entries}}                         &  32              \\ \midrule
 \multicolumn{2}{|c|}{\textbf{LSQ entries}}                        & 8 / 8           \\ \midrule
 \multicolumn{2}{|c|}{\textbf{ROB entries}}                        & 40              \\ \bottomrule
 \end{tabular}%
 }
 \caption{My caption}
 \label{my-label}
 \end{table}

but I keep getting a table like this image:

enter image description here

It's so big but I can deal with the size, but the borders are not good.
Anyone can help?

  • 4
    Welcome! Using booktabs and then trying to use vertical rules is not recommended. From the booktabs documentation: "More importantly the rules generated by the new commands are in no way guaranteed to connect with verticals generated by {|} characters in the preamble. This is a feature (see above). You should not use vertical rules in tables, end of story." – Paul Gessler Aug 20 '16 at 17:26
  • Any alternative for booktabs that goes fine with this kind of tables – A.nechi Aug 20 '16 at 17:33
  • 3
    if you want vertical rules just remove booktabs and use standard latex commands – David Carlisle Aug 20 '16 at 17:40
  • I'm surprised you get any output with that code. I always need a document class and the document environment to avoid compilation errors. makecell etc. are alternatives, but professional-quality tables don't have vertical rules in the vast majority of cases. – cfr Aug 20 '16 at 17:41
  • 1
    don't do \resizebox{\textwidth}{!}{% to tables it just destroys any attempts at consistent document formatting and renders the table at an arbitrary font size. – David Carlisle Aug 20 '16 at 17:42
4

A "classic" table design, with use of the \hline instead \booktabs rules, vertical spaces in cells are increased by \renewcommand\arraystretch{1.2} (if you like to have more vertical space, increase \arraystretch) and some effort to make code as simple as possible and concise by use of two new commands and defined columns to use \bfseries font:

\documentclass{article}
%    \usepackage[showframe]{geometry}
\usepackage{array,multirow}
\newcommand\mcbf[1]{\multicolumn{2}{|c|}{\textbf{#1}}}
\newcommand\mlbf[1]{\multicolumn{2}{|l|}{\textbf{#1}}}
\usepackage{graphicx}

    \begin{document}
\begin{table}[htb]
\centering
\renewcommand\arraystretch{1.2}
    \begin{tabular}{|>{\bfseries}c|>{\bfseries}l|c|}
    \hline
\mcbf{Cortex A9 Parameters}                         & \textbf{Values}   \\ \hline
\mcbf{Core clock}                                   & 800 MHz           \\ \hline
\multirow{5}{*}{L2}             &  Size             & 512 kB            \\ \cline{2-3}
                                &  Associativity    & 8                 \\ \cline{2-3}
                                &  Latency          & 8                 \\ \cline{2-3}
                                &  MSHRs            & 11                \\ \cline{2-3}
                                &  Write buffers    & 9                 \\ \hline
 \multirow{4}{*}{L1 - I}        &  Size             & 32 kB             \\ \cline{2-3}
                                &  Associativity    & 4                 \\ \cline{2-3}
                                &  Latency          & 1                 \\ \cline{2-3}
                                &  MSHRs            & 2                 \\ \hline
 \multirow{5}{*}{L1 - D}        &  Size             & 32 kB             \\ \cline{2-3}
                                &  Associativity    & 4                 \\ \cline{2-3}
                                &  Latency          & 1                 \\ \cline{2-3}
                                &  MSHRs            & 4                 \\ \cline{2-3}
                                &  Write buffers    & 16                \\ \hline
 {Stride prefetcher}            &  Degree           & 1                 \\ \hline
 \multirow{2}{*}{Global BP}     &  Entries          & 4096              \\ \cline{2-3}
                                &  Bits             & 2                 \\ \hline
\mlbf{BTB entries}                                  & 4096              \\ \hline
\mlbf{Return Address Stack (RAS) entries}           & 8                 \\ \hline
\mlbf{Issues width}                                 & 2                 \\ \hline
\mlbf{Pipeline stages}                              & 8                 \\ \hline
\mlbf{Physical INT registers}                       & 62                \\ \hline
\mlbf{Physical FP registers}                        & 256               \\  \hline
\mlbf{IQ entries}                                   & 32                \\ \hline
\mlbf{LSQ entries}                                  & 8 / 8             \\ \hline
\mlbf{ROB entries}                                  & 40                \\ \hline
 \end{tabular}%
    \caption{My caption}
 \label{my-label}
    \end{table}
 \end{document}

enter image description here

5

Not only should you omit all vertical rules from the table (trust me, they're not needed, and they won't be misssd...), you should also get rid of all horizontal rules in the interior of the table. Omit the \cmidrule directives entirely, and replace all interior instances of \midrule with \addlinespace. You

Furthermore, there's really no need to provide any bold-facing of the tabular material. In fact, your readers will likely appreciate not being attacked, typographically speaking, by the equivalent of ceaseless shouting.

enter image description here

\documentclass{article}
\usepackage{booktabs}
\newcommand\mcl[1]{\multicolumn{2}{@{}l}{#1}} % handy shortcut macro
\begin{document}
\begin{table}[h!]
\centering
\begin{tabular}{@{}llc@{}}
\toprule
\mcl{Cortex A9 Parameters} & Values \\ 
\midrule
\mcl{Core clock}                & 800 MHz \\[1.5ex]
L2           & Size             & 512 kB \\              
             & Associativity    & 8   \\              
             & Latency          & 8 \\              
             & MSHRs            & 11 \\              
             & Write buffers    & 9 \\[1.5ex]
L1 - I      & Size              & 32 kBm\\             
            & Associativity     & 4 \\             
            & Latency           & 1 \\             
            & MSHRs             & 2 \\[1.5ex]
L1 - D      & Size             & 32 kB  \\             
            & Associativity    & 4 \\             
            & Latency          & 1 \\             
            & MSHRs            & 4 \\             
            & Write buffers    & 16 \\[1.5ex]
Stride prefetcher & Degree     & 1 \\ 
\addlinespace
Global BP   & Entries          & 4096 \\             
            & Bits             & 2 \\ 
\addlinespace
\mcl{BTB entries}              & 4096  \\ 
\mcl{Return Address Stack (RAS) entries} & 8 \\ 
\mcl{Issues width}             & 2 \\ 
\mcl{Pipeline stages}          & 8 \\ 
\mcl{Physical INT registers}   & 62\\ 
\mcl{Physical FP registers}    & 256 \\ 
\mcl{IQ entries}               & 32 \\ 
\mcl{LSQ entries}              & 8 / 8 \\ 
\mcl{ROB entries}              & 40 \\ 
\bottomrule
\end{tabular}
 \caption{My caption}
 \label{my-label}
\end{table}
\end{document}
  • I think you can add some more vertical space to make L groups stand out a bit – percusse Aug 20 '16 at 20:18
  • @percusse - Thanks for this suggestion! I've increased the vertical space between the lines in question to 1.5ex. – Mico Aug 21 '16 at 6:20
4

Either use booktabs or vertical lines, not both (and never scale the table, if you need to change the size, use a specific size such as \small)

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array}

\begin{document}


\begin{table}
\centering

\begin{tabular}{clc}
\toprule
\multicolumn{2}{c}{\textbf{Cortex A9 Parameters}}               &     \textbf{Values} \\ \midrule
\multicolumn{2}{c}{\textbf{Core clock}}                         & 800 MHz         \\ \midrule
\multirow{5}{*}{\textbf{L2}}           & \textbf{Size}            & 512 kB          \\ \cmidrule(l){2-3} 
                                   & \textbf{Associativity}   & 8               \\ \cmidrule(l){2-3} 
                                   & \textbf{Latency}         & 8               \\ \cmidrule(l){2-3} 
                                   & \textbf{MSHRs}           & 11              \\ \cmidrule(l){2-3} 
                                   & \textbf{Write buffers}   & 9               \\ \midrule
 \multirow{4}{*}{\textbf{L1 - I}}       & \textbf{Size}            & 32 kB           \\ \cmidrule(l){2-3} 
                                   & \textbf{Associativity}   & 4               \\ \cmidrule(l){2-3} 
                                   & \textbf{Latency}         & 1               \\ \cmidrule(l){2-3} 
                                   & \textbf{MSHRs}           & 2               \\ \midrule
 \multirow{5}{*}{\textbf{L1 - D}}       & \textbf{Size}            & 32 kB           \\ \cmidrule(l){2-3} 
                                   & \textbf{Associativity}   & 4               \\ \cmidrule(l){2-3} 
                                   & \textbf{Latency}         & 1               \\ \cmidrule(l){2-3} 
                                   & \textbf{MSHRs}           & 4               \\ \cmidrule(l){2-3} 
                                   & \textbf{Write buffers}   & 16              \\ \midrule
 \textbf{Stride prefetcher}             & \textbf{Degree}          & 1               \\ \midrule
 \multirow{2}{*}{\textbf{Global BP}}    & \textbf{Entries}         & 4096            \\ \cmidrule(l){2-3} 
                                   & \textbf{Bits}            & 2               \\ \midrule
 \multicolumn{2}{l}{\textbf{BTB entries}}                        & 4096            \\ \midrule
 \multicolumn{2}{l}{\textbf{Return Address Stack (RAS) entries}} & 8               \\ \midrule
 \multicolumn{2}{l}{\textbf{Issues width}}                       & 2               \\ \midrule
 \multicolumn{2}{l}{\textbf{Pipeline stages}}                    & 8               \\ \midrule
 \multicolumn{2}{l}{\textbf{Physical INT registers}}             & 62              \\ \midrule
 \multicolumn{2}{l}{\textbf{Physical FP registers}}              & 256             \\ \midrule
 \multicolumn{2}{l}{\textbf{IQ entries}}                         &  32              \\ \midrule
 \multicolumn{2}{l}{\textbf{LSQ entries}}                        & 8 / 8           \\ \midrule
 \multicolumn{2}{l}{\textbf{ROB entries}}                        & 40              \\ \bottomrule
 \end{tabular}%

 \caption{My caption}
 \label{my-label}

\end{table}
\begin{table}
\addtolength\extrarowheight{2pt}
\begin{tabular}{@{}|c|l|c|@{}}
\hline
\multicolumn{2}{|c|}{\textbf{Cortex A9 Parameters}}               &     \textbf{Values} \\ \hline
\multicolumn{2}{|c|}{\textbf{Core clock}}                         & 800 MHz         \\ \hline
\multirow{5}{*}{\textbf{L2}}           & \textbf{Size}            & 512 kB          \\ \cline{2-3} 
                                   & \textbf{Associativity}   & 8               \\ \cline{2-3} 
                                   & \textbf{Latency}         & 8               \\ \cline{2-3} 
                                   & \textbf{MSHRs}           & 11              \\ \cline{2-3} 
                                   & \textbf{Write buffers}   & 9               \\ \hline
 \multirow{4}{*}{\textbf{L1 - I}}       & \textbf{Size}            & 32 kB           \\ \cline{2-3} 
                                   & \textbf{Associativity}   & 4               \\ \cline{2-3} 
                                   & \textbf{Latency}         & 1               \\ \cline{2-3} 
                                   & \textbf{MSHRs}           & 2               \\ \hline
 \multirow{5}{*}{\textbf{L1 - D}}       & \textbf{Size}            & 32 kB           \\ \cline{2-3} 
                                   & \textbf{Associativity}   & 4               \\ \cline{2-3} 
                                   & \textbf{Latency}         & 1               \\ \cline{2-3} 
                                   & \textbf{MSHRs}           & 4               \\ \cline{2-3} 
                                   & \textbf{Write buffers}   & 16              \\ \hline
 \textbf{Stride prefetcher}             & \textbf{Degree}          & 1               \\ \hline
 \multirow{2}{*}{\textbf{Global BP}}    & \textbf{Entries}         & 4096            \\ \cline{2-3} 
                                   & \textbf{Bits}            & 2               \\ \hline
 \multicolumn{2}{|l|}{\textbf{BTB entries}}                        & 4096            \\ \hline
 \multicolumn{2}{|l|}{\textbf{Return Address Stack (RAS) entries}} & 8               \\ \hline
 \multicolumn{2}{|l|}{\textbf{Issues width}}                       & 2               \\ \hline
 \multicolumn{2}{|l|}{\textbf{Pipeline stages}}                    & 8               \\ \hline
 \multicolumn{2}{|l|}{\textbf{Physical INT registers}}             & 62              \\ \hline
 \multicolumn{2}{|l|}{\textbf{Physical FP registers}}              & 256             \\ \hline
 \multicolumn{2}{|l|}{\textbf{IQ entries}}                         &  32              \\ \hline
 \multicolumn{2}{|l|}{\textbf{LSQ entries}}                        & 8 / 8           \\ \hline
 \multicolumn{2}{|l|}{\textbf{ROB entries}}                        & 40              \\ \hline
 \end{tabular}%

 \caption{My caption}
 \label{my-label2}
 \end{table}

\end{document}
4

Your problems come from booktabs adding vertical padding round horizontal lines. I set this padding to 0pt, and replaced it with \makegapedcells from makecell. Further, I replaced the \multirow command with \makecell, which allows for line breaks in cells, and I removes many horizontal rules. Also, you should not use \resizebox for tables, it looks ugly. In the present case, you don't need it to fits the table between the margins.

Here is a simplified code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{multirow, makecell}
\usepackage{graphicx}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.2pt}

\begin{document}

\begin{table}[!ht]
  \centering\setlength\aboverulesep{0pt}\setlength\belowrulesep{0pt}
  \bfseries
  \renewcommand\cellset{\renewcommand\arraystretch{0.5}}
  \setcellgapes{4.5pt}\makegapedcells
  \begin{tabular}{@{}|c|l|>{\normalfont}c|@{}}
    \toprule
    \multicolumn{2}{|c|}{Cortex A9 Parameters} & \textbf{Values} \\ \midrule
    \multicolumn{2}{|c|}{Core clock} & 800 MHz \\ \midrule
    L2                         & \makecell[l]{Size  \\ Associativity \\ Latency \\ MSHRs \\ Write buffers } & \makecell{512 kB \\ 8 \\ 8 \\ 11 \\ 9} \\ %
    \midrule
    L1 - I                     & \makecell[l]{Size  \\ Associativity \\ Latency \\ MSHRs }  &  \makecell{32 kB \\ 4 \\ 1 \\ 2}  \\ %
    \midrule
    L1 - D                     & \makecell[l]{Size  \\ Associativity \\ Latency \\ MSHRs \\ Write buffers} & \makecell{32 kB \\ 4 \\ 1 \\ 4 \\ 16} \\ %
    \midrule
    Stride prefetcher          & Degree            & 1    \\ \midrule
    Global BP  & \makecell{Entries \\ Bits }          & \makecell{4096 \\ 2}  \\ %
    \midrule
    \multicolumn{2}{|c|}{BTB entries} & 4096 \\ \midrule
    \multicolumn{2}{|c|}{Return Address Stack (RAS) entries} & 8 \\ \midrule
    \multicolumn{2}{|c|}{Issues width} & 2 \\ \midrule
    \multicolumn{2}{|c|}{Pipeline stages} & 8 \\ \midrule
    \multicolumn{2}{|c|}{Physical INT registers} & 62 \\ \midrule
    \multicolumn{2}{|c|}{Physical FP registers} & 256 \\ \midrule
    \multicolumn{2}{|c|}{IQ entries} & 32 \\ \midrule
    \multicolumn{2}{|c|}{LSQ entries} & 8 / 8 \\ \midrule
    \multicolumn{2}{|c|}{ROB entries} & 40 \\ \bottomrule
  \end{tabular}%
  \caption{My caption}
  \label{my-label}
\end{table}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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