如何设置表格中行与行之间的间距

如何设置表格中行与行之间的间距
\begin{table}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{|*{4}{c|}} 
    \toprule
    \multirow{2}[2]{*}{\textbf{Empresa ``i"}} & \multirow{2}[2]{*}{\textbf{Variable}} & \multirow{2}[2]{*}{\textbf{Modalidad}} & \multirow{2}[2]{*}{\textbf{Dirigido  a}} \\
          &       &       &  \\
    \midrule
    \multirow{18}[36]{*}{\textbf{E_i}} & \multirow{6}[12]{*}{Líneas en servicio} & \multirow{2}[4]{*}{Postpago} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
\cmidrule{3-4}          &       & \multirow{2}[4]{*}{Control} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
\cmidrule{3-4}          &       & \multirow{2}[4]{*}{Prepago} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
\cmidrule{2-4}          & \multirow{6}[12]{*}{Tráfico Facturado} & \multirow{2}[4]{*}{Postpago} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
\cmidrule{3-4}          &       & \multirow{2}[4]{*}{Control} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
\cmidrule{3-4}          &       & \multirow{2}[4]{*}{Prepago} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
\cmidrule{2-4}          & \multirow{6}[12]{*}{Ingresos} & \multirow{2}[4]{*}{Postpago} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
\cmidrule{3-4}          &       & \multirow{2}[4]{*}{Control} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
\cmidrule{3-4}          &       & \multirow{2}[4]{*}{Prepago} & Comercial \\
\cmidrule{4-4}          &       &       & Residencial \\
    \bottomrule
    \end{tabular}%
  \label{tab:addlabel}%
\end{table}%

这是我的代码,我真的想修复表格,使之看起来行与行之间没有空格。请帮忙

答案1

使用该软件包的基本建议booktabs是:“省略所有垂直线”。它们不是必需的。真的。

将此规则应用于本表,您应该替换

\begin{tabular}{|*{4}{c|}}

\begin{tabular}{*{4}{c}}

答案2

我假设您希望获得如下内容:

enter image description here

我删除了所有booktabs规则并将其替换为 和\hline\cline并删除了不必要的移动multrow单元格,得到了上面的图像。我还使用makecellthead来设置列标题。将\arraystretch默认设置1为后,表格中的行间距更大1.5

\documentclass{article}
\usepackage{makecell,multirow}
\renewcommand\theadfont{\bfseries\normalsize}
\usepackage{caption}

\begin{document}
\begin{table}[htbp]
  \centering
  \renewcommand\arraystretch{1.5}
  \caption{Add caption}
    \begin{tabular}{|*{4}{c|}}
    \hline
\thead{Empresa ``i"} & \thead{Variable}  &  \thead{Modalidad} & \thead{Dirigido  a} \\
    \hline
\multirow{18}{*}{\textbf{E\_i}} & \multirow{6}{*}{Líneas en servicio} & \multirow{2}{*}{Postpago} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
\cline{3-4}          &       & \multirow{2}{*}{Control} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
\cline{3-4}          &       & \multirow{2}{*}{Prepago} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
\cline{2-4}          & \multirow{6}{*}{Tráfico Facturado} & \multirow{2}[4]{*}{Postpago} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
\cline{3-4}          &       & \multirow{2}{*}{Control} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
\cline{3-4}          &       & \multirow{2}{*}{Prepago} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
\cline{2-4}          & \multirow{6}{*}{Ingresos} & \multirow{2}[4]{*}{Postpago} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
\cline{3-4}          &       & \multirow{2}{*}{Control} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
\cline{3-4}          &       & \multirow{2}{*}{Prepago} & Comercial \\
\cline{4-4}          &       &       & Residencial \\
    \hline
    \end{tabular}
  \label{tab:addlabel}
\end{table}
\end{document}

答案3

我提出了两种可能的布局:第一种是@Zarlo 解决方案的变体,代码更简单(没有任何\multirow)且水平线更少。第二种使用更少的水平线和一些垂直线。

\documentclass[letter]{article}
\usepackage[utf8]{inputenc} %
\usepackage[T1]{fontenc}%
\usepackage{lmodern} %
\usepackage{graphicx,array,multirow, makecell, booktabs, caption}
\renewcommand\theadfont{\normalsize\bfseries}
\newcommand\ComRes{\ensuremath{\left[\begin{tabular}{l@{}}Comercial\\[-0.3ex]Residencial \end{tabular}\right.}}

\begin{document}

\begin{table}[htbp]
\centering \caption{Add caption} %
\setlength\aboverulesep{0pt}
\setlength\belowrulesep{0pt}
\setcellgapes{3pt}\makegapedcells
\begin{tabular}{|*{4}{c|}}
\toprule%multirow{2}[2]{*}
 \thead{Empresa “i”} & \thead{Variable} & \thead{Modalidad} & \thead{Dirigido a} \\%
 \midrule %
 & & Postpago & \makecell{Comercial \\ Residencial}\\%
\cmidrule{3-4}%
 & Líneas en servicio & Control & \makecell{Comercial \\ Residencial}\\%
\cmidrule{3-4}%
 & & Prepago &\makecell{ Comercial \\ Residencial }\\%
%%%%%%%%%
 \cmidrule{2-4}%
  & & Postpago & \makecell{Comercial \\ Residencial}\\%%
\cmidrule{3-4}%
\textbf{E\textsubscript{i}} & Tráfico Facturado & Control & \makecell{Comercial \\ Residencial}\\%
 \cmidrule{3-4}%
 & & Prepago &\makecell{ Comercial \\ Residencial }\\%
%%%%%%%%%
 \cmidrule{2-4}%
  & & Postpago & \makecell{Comercial \\ Residencial}\\%
 \cmidrule{3-4}%
  & Ingresos & Control & \makecell{Comercial \\ Residencial}\\%
 \cmidrule{3-4}%
 & & Prepago &\makecell{ Comercial \\ Residencial }\\%%
 \bottomrule%
 \end{tabular}%
 \label{tab1:addlabel}
 \end{table}%
\begin{table}[htbp]
\centering \caption{Add caption} %
\setcellgapes{3pt}\makegapedcells
\begin{tabular}{cr!{\vrule width 1.2pt}c c}
\toprule%multirow{2}[2]{*}
 \thead{Empresa “i”} & \multicolumn{1}{c}{\thead{Variable}} & \multicolumn{1}{c}{\thead{Modalidad}} & \thead{Dirigido a} \\%
 \midrule
 \addlinespace %
 & & Postpago & \ComRes \\%
 & Líneas en servicio & Control & \ComRes \\%
 & & Prepago & \ComRes \\%
\addlinespace[1.5ex]
  & & Postpago & \ComRes \\%%
\textbf{E\textsubscript{i}} & Tráfico Facturado & Control & \ComRes \\%
 & & Prepago & \ComRes \\%
\addlinespace[1.5ex]
  & & Postpago & \ComRes \\%
  & Ingresos & Control & \ComRes \\%
 & & Prepago & \ComRes \\%
 \addlinespace
 \bottomrule%
 \end{tabular}%
 \label{tab2:addlabel}
 \end{table}

 \end{document} 

enter image description here enter image description here

相关内容