格式化 LaTeX 表格(多行)

格式化 LaTeX 表格(多行)

我正在尝试格式化 LaTeX 表格(我使用 ShareLaTeX online),我想做一些特别的事情,但我似乎不知道该怎么做。我认为这涉及使用多行命令,但我不确定。我的代码:

\begin{table}[h!]
\centering
\caption{VFD Parameter Settings (User and Basic)}
\label{tab: VFD Parameter Settings1}
\begin{tabular}{|l|l|l|p{3cm}|p{4.5cm}|}
\hline
Setting     & Function                 & Value     & Units/Description          & Source/Reasoning                                                  \\ \hline \hline
00-10       & Control Mode             & 0         & Speed Mode                 & To control speed                                                  \\ \hline
00-11       & Control of Speed Mode    & 6         & PM Sensorless              & (Open-Loop) For use with PMAC motors                              \\ \hline
            &                          & 4         & PM Vector + Encoder        & (Closed-Loop) For Encoder control                                 \\ \hline
00-20       & Source of Freq. Command  & 0         & Digital Keypad             & (Manual) Manually control freq. w/ keypad                         \\ \hline
            &                          & 5         & Pulse Input w/ Direction   & (Auto) To control speed with Arduino pulses                       \\ \hline
00-21       & Source of Op. Command    & 0         & Digital Keypad             & (Manual) Manually control Start/Stop w/ keypad                    \\ \hline
            &                          & 1         & External Terminals         & (Auto) To control Start/Stop with Arduino                         \\ \hline
00-23       & Control Motor Direction  & 0         & Enable Fwd/Rev             & Allow for both fwd and rev motion                                 \\ \hline
00-32       & Keypad STOP function     & 1         & STOP key enabled           & Allows for STOP key to work in auto mode                          \\ \hline
01-00       & Max Operation Frequency  & 200       & Hz                         & Frequency for rated speed of 3000RPM                              \\ \hline
01-01       & Output Frequency         & *variable & Hz                         & (Open-Loop) Controls motor speed. Generally used 20-50Hz.         \\ \hline
01-02       & Output Voltage           & 115       & Vrms                       & Rated Bus Voltage from actuator nameplate                         \\ \hline
01-12       & Acceleration Time        & *variable & seconds                    & Controls speed to ramp up. Used .05s.                             \\ \hline
01-13       & Deceleration Time        & *variable & seconds                    & Controls speed to ramp down. Used .05s.                           \\ \hline
01-45       & Time Unit of Accel/Decel & 0         & 0.01 seconds               & So accel/decel time is in units of 0.01s                          \\ \hline
\end{tabular}
\end{table}

编译结果如下: 在此处输入图片描述

对于参数 00-11、00-20 和 00-21,我想合并并居中前两列的两行,消除空白单元格。我想明确指出这些参数根据控件类型有两个选项。以下是我希望它在 MS Excel 中显示的样子的示例: 在此处输入图片描述

我该怎么做?我也知道格式总体来说不太好,如果您能推荐其他修复方法我将不胜感激。

答案1

m对于最后一列和\multirow要合并的单元格使用将相应的\hlines 更改为\clines。

\documentclass{article}
\usepackage{array,multirow}
\usepackage[margin=1in]{geometry}
\begin{document}

\newcommand*{\mr}[1]{\multirow{2}[4]{*}{#1}}

\begin{table}
\centering
\caption{VFD Parameter Settings (User and Basic)}
\label{tab: VFD Parameter Settings1}
\begin{tabular}{|l|l|l|>{\raggedright}m{3cm}|m{4.5cm}|}
\hline
Setting    & Function                   & Value     & Units/Description          & Source/Reasoning                                                  \\ \hline \hline
00-10      & Control Mode               & 0         & Speed Mode                 & To control speed                                                  \\ \hline
\mr{00-11} &\mr{Control of Speed Mode}  & 6         & PM Sensorless              & (Open-Loop) For use with PMAC motors                              \\ \cline{3-5}
           &                            & 4         & PM Vector + Encoder        & (Closed-Loop) For Encoder control                                 \\ \hline
\mr{00-20} &\mr{Source of Freq. Command}& 0         & Digital Keypad             & (Manual) Manually control freq. w/ keypad                         \\ \cline{3-5}
           &                            & 5         & Pulse Input w/Direction   & (Auto) To control speed with Arduino pulses                       \\ \hline
\mr{00-21} &\mr{Source of Op. Command}  & 0         & Digital Keypad             & (Manual) Manually control Start/Stop w/ keypad                    \\ \cline{3-5}
           &                            & 1         & External Terminals         & (Auto) To control Start/Stop with Arduino                         \\ \hline
00-23      & Control Motor Direction    & 0         & Enable Fwd/Rev             & Allow for both fwd and rev motion                                 \\ \hline
00-32      & Keypad STOP function       & 1         & STOP key enabled           & Allows for STOP key to work in auto mode                          \\ \hline
01-00      & Max Operation Frequency    & 200       & Hz                         & Frequency for rated speed of 3000RPM                              \\ \hline
01-01      & Output Frequency           & *variable & Hz                         & (Open-Loop) Controls motor speed. Generally used 20-50Hz.         \\ \hline
01-02      & Output Voltage             & 115       & Vrms                       & Rated Bus Voltage from actuator nameplate                         \\ \hline
01-12      & Acceleration Time          & *variable & seconds                    & Controls speed to ramp up. Used .05s.                             \\ \hline
01-13      & Deceleration Time          & *variable & seconds                    & Controls speed to ramp down. Used .05s.                           \\ \hline
01-45      & Time Unit of Accel/Decel   & 0         & 0.01 seconds               & So accel/decel time is in units of 0.01s                          \\ \hline
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

答案2

以下是一些改进和简化:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{ragged2e}
\usepackage[table, svgnames]{xcolor}
\usepackage{array, multirow, caption, hhline}

\newcommand\colhead[1]{\multicolumn{1}{c}{\bfseries#1}}
\newcommand\myhhline{\hhline{>{\arrayrulecolor{black}}|>{\arrayrulecolor{Gainsboro}}-|-|-|-|->{\arrayrulecolor{black}}|}}

\begin{document}

\begin{table}[!htb]
  \centering\setlength\tabcolsep{3pt}
\renewcommand{\arraystretch}{1.5}
\setlength\arrayrulewidth{0.8pt}
  \caption{VFD Parameter Settings (User and Basic)}
  \label{tab: VFD Parameter Settings1}
  \begin{tabular}{|l!{\color{Gainsboro}\vrule width1pt}l!{\color{Gainsboro}\vrule width1pt}l!{\color{Gainsboro}\vrule width1pt}>{\RaggedRight}m{3cm}!{\color{Gainsboro}\vrule width1pt}>{\RaggedRight}m{4cm}|}
 \colhead{Setting} & \colhead{Function} & \colhead{Value} & \colhead{Units/Description} & \colhead{Source/Reasoning} \\[1ex]
\hline
    00-10 & Control Mode & 0 & Speed Mode & To control speed \\ \myhhline
    00-11 & Control of Speed Mode & 6 & PM Sensorless & (Open-Loop) For use with PMAC motors \\ \myhhline
            & & 4 & PM Vector + Encoder & (Closed-Loop) For Encoder control \\ \myhhline
    00-20 & Source of Freq. Command & 0 & Digital Keypad & (Manual) Manually control freq. w/ keypad \\ \myhhline
            & & 5 & Pulse Input w/ Direction & (Auto) To control speed with Arduino pulses \\ \myhhline
    00-21 & Source of Op. Command & 0 & Digital Keypad & (Manual) Manually control Start/Stop w/ keypad \\ \myhhline
            & & 1 & External Terminals & (Auto) To control Start/Stop with Arduino \\ \myhhline
    00-23 & Control Motor Direction & 0 & Enable Fwd/Rev & Allow for both fwd and rev motion \\ \myhhline
    00-32 & Keypad STOP function & 1 & STOP key enabled & Allows for STOP key to work in auto mode \\ \myhhline
    01-00 & Max Operation Frequency & 200 & Hz & Frequency for rated speed of 3000RPM \\ \myhhline
    01-01 & Output Frequency & *variable & Hz & (Open-Loop) Controls motor speed. Generally used 20-50Hz. \\ \myhhline
    01-02 & Output Voltage & 115 & Vrms & Rated Bus Voltage from actuator nameplate \\ \myhhline
    01-12 & Acceleration Time & *variable & seconds & Controls speed to ramp up. Used .05s. \\ \myhhline
    01-13 & Deceleration Time & *variable & seconds & Controls speed to ramp down. Used .05s. \\ \myhhline
    01-45 & Time Unit of Accel/Decel & 0 & 0.01 seconds & So accel/decel time is in units of 0.01s \\ \hline
  \end{tabular}
\end{table}

\end{document} 

在此处输入图片描述

相关内容