我需要连接表格的垂直线(@符号,值,渐变)。考虑过multirow
/multicolum
但没能解决。
\documentclass[a4paper,12pt,headsepline]{scrreprt}
\usepackage{longtable}
\usepackage{multicol}
\usepackage{multirow}
\begin{document}
\begin{center}
\begin{table}[H]
\captionabove{Caption}
\label{tab:TYPETURBSTREAM}
\begin{tabular}{|c|c|c|c|}
\hline
LONG TEXT TEXT TEXT TEXT \\/ NEXT LINE & Symbol & VALUE & GRADIENT \\ \hline
A & A1 & A2 & zeroGradient \\ \hline
B & B1 & B2 & B3 \\ \hline
C & C1 & C2 & C3 \\ \hline
D & D1 & D2 & D3 \\ \hline
E & D1 & E2 & E3 \\ \hline
\end{tabular}
\end{table}
\end{center}
\end{document}
答案1
尽管我更喜欢 Zarko 的回答,但没有人指出 OP能\multirow
用和做他想做的事 \multicolumn
,也可以使用pbox
或嵌套的tabular
(就像@egreg 的这个回答一样):
\documentclass[a4paper,12pt,headsepline]{scrreprt}
\usepackage{array,pbox, multirow}
\newcommand{\specialcell}[2][c]{% Command by @egreg (https://tex.stackexchange.com/a/19678/81905)
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}
\newcommand{\tablecode}[2]{%
\begin{table}
\centering
\captionabove{#1}
\begin{tabular}{|c|c|c|c|}
\hline
#2 & Symbol & VALUE & GRADIENT \\ \hline
A & A1 & A2 & zeroGradient \\ \hline
B & B1 & B2 & B3 \\ \hline
C & C1 & C2 & C3 \\ \hline
D & D1 & D2 & D3 \\ \hline
E & D1 & E2 & E3 \\ \hline
\end{tabular}
\end{table}%
}
\begin{document}
\tablecode{Using fixed width column with \texttt{\textbackslash multicolumn}}%
{\multicolumn{1}{|>{\centering\arraybackslash}m{6.75cm}|}{LONG TEXT TEXT TEXT TEXT\newline / NEXT LINE}}
\tablecode{Using \texttt{pbox}}%
{\pbox{\textwidth}{\relax\ifvmode\centering\fi LONG TEXT TEXT TEXT TEXT \\ / NEXT LINE}}
\tablecode{Using nested \texttt{tabular}'s}%
{\specialcell{LONG TEXT TEXT TEXT TEXT \\ / NEXT LINE}}
\begin{table}
\centering
\captionabove{Using \texttt{\textbackslash multirow}}
\begin{tabular}{|c|c|c|c|}
\hline
LONG TEXT TEXT TEXT TEXT & \multirow{2}{*}{Symbol} & \multirow{2}{*}{VALUE} & \multirow{2}{*}{GRADIENT} \\
/ NEXT LINE & & & \\
\hline
A & A1 & A2 & zeroGradient \\ \hline
B & B1 & B2 & B3 \\ \hline
C & C1 & C2 & C3 \\ \hline
D & D1 & D2 & D3 \\ \hline
E & D1 & E2 & E3 \\ \hline
\end{tabular}
\end{table}
\end{document}
答案2
您只需在第一行的末尾添加(空)单元格,即&&&
在之后添加LONG TEXT..
。
此外,table
在环境中再放置一个环境center
也没有多大意义,而且无论如何它也不会使表格居中。最好删除center
环境并\centering
在其后添加\begin{table}
。
如果您确实想用作[H]
浮点说明符,则需要\usepackage{float}
,但您的代码中缺少它。
\documentclass[a4paper,12pt,headsepline]{scrreprt}
\begin{document}
\begin{table}
\centering
\captionabove{Caption}
\label{tab:TYPETURBSTREAM}
\begin{tabular}{|c|c|c|c|}
\hline
LONG TEXT TEXT TEXT TEXT &&& \\
/ NEXT LINE & Symbol & VALUE & GRADIENT \\ \hline
A & A1 & A2 & zeroGradient \\ \hline
B & B1 & B2 & B3 \\ \hline
C & C1 & C2 & C3 \\ \hline
D & D1 & D2 & D3 \\ \hline
E & D1 & E2 & E3 \\ \hline
\end{tabular}
\end{table}
\end{document}
答案3
解决问题的一致且清晰的方法提供了makecell
来自包的宏makecell
,通过它您可以优雅地合并表中的前两行:
\documentclass[a4paper,12pt,headsepline]{scrreprt}
\usepackage{makecell}
\begin{document}
\begin{table}
\centering
\captionabove{Caption}
\label{tab:TYPETURBSTREAM}
\begin{tabular}{|c|c|c|c|}
\hline
\makecell[b]{LONG TEXT TEXT TEXT TEXT\\
/ NEXT LINE}
& Symbol & VALUE & GRADIENT \\ \hline
A & A1 & A2 & zeroGradient \\ \hline
B & B1 & B2 & B3 \\ \hline
C & C1 & C2 & C3 \\ \hline
D & D1 & D2 & D3 \\ \hline
E & D1 & E2 & E3 \\ \hline
\end{tabular}
\end{table}
\end{document}
附录:
一个有吸引力的替代解决方案是使用列类型,它会自动将单元格文本拆分为更多行(如 Guilherme Zanotelli 在他的答案中展示的第一个示例)。让我使用包提供的可能性来扩展和简化此示例array
:
\documentclass[a4paper,12pt,headsepline]{scrreprt}
\usepackage{array}
\begin{document}
\begin{table}
\centering
\captionabove{Caption}
\label{tab:TYPETURBSTREAM}
\begin{tabular}{|>{\centering}p{6cm}|c|c|c|}% since this is not lst column, the use of \arraybackslash can be omitted ...
\hline
LONG TEXT TEXT TEXT NEXT IN MORE LINES
& Symbol & VALUE & GRADIENT \\ \hline
A & A1 & A2 & zeroGradient \\ \hline
B & B1 & B2 & B3 \\ \hline
\end{tabular}
\bigskip
\begin{tabular}{|>{\centering}m{6cm}|c|c|c|}
\hline
LONG TEXT TEXT TEXT NEXT IN MORE LINES
& Symbol & VALUE & GRADIENT \\ \hline
A & A1 & A2 & zeroGradient \\ \hline
B & B1 & B2 & B3 \\ \hline
\end{tabular}
\bigskip
\begin{tabular}{|>{\centering}b{6cm}|c|c|c|}
\hline
LONG TEXT TEXT TEXT NEXT IN MORE LINES
& Symbol & VALUE & GRADIENT \\ \hline
A & A1 & A2 & zeroGradient \\ \hline
B & B1 & B2 & B3 \\ \hline
\end{tabular}
\end{table}
\end{document}