表格格式不完美

表格格式不完美

我是 LaTeX 新手。因此,我应该创建一个表格,代码如下:

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

但我一直得到像这样的表格:

在此处输入图片描述

它很大,但我可以接受这个尺寸,但边框不太好。
有人可以帮忙吗?

答案1

一种“经典”的表格设计,使用\hline替代\booktabs规则,单元格中的垂直空间增加了\renewcommand\arraystretch{1.2}(如果您希望拥有更多的垂直空间,请增加\arraystretch),并通过使用两个新命令和定义的列来使用字体,使代码尽可能简单和简洁\bfseries

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

在此处输入图片描述

答案2

你不仅应该从表格中省略所有垂直规则(相信我,它们是不需要的,而且它们不会被遗漏……),你还应该摆脱全部水平线内部的表格。\cmidrule完全省略指令,并将所有内部实例替换为\midrule\addlinespace

此外,表格内容确实没必要加粗。事实上,从排版角度来说,您的读者可能会喜欢不被无休止的叫喊所攻击。

在此处输入图片描述

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

答案3

要么使用书形标签,要么使用垂直线,不能同时使用两者(并且永远不要缩放表格,如果需要更改大小,请使用特定大小,例如\small

在此处输入图片描述

\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

您的问题来自于在booktabs水平线周围添加垂直填充。我将此填充设置为 0pt,并将其替换为\makegapedcellsmakecell此外,我将\multirow 命令替换为\makecell,这允许在单元格中换行,并且我删除了许多水平规则。此外,您不应该将其用于\resizebox表格,它看起来很丑陋。在本例中,您不需要它来适应边距之间的表格。

以下是简化的代码:

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

在此处输入图片描述

相关内容