我正在尝试创建一个表,但有些东西不对劲。我是新手LaTeX
,所以即使达到这个状态也不容易。
- 用青色标记的线条缺失了。
- 用红色标记的线不应该被画出来。
- 如果可能的话,蓝色框内的文本应该水平居中,并且位于单元格的底部。
- 另外,是否可以将绿色框内的方程式作为多行内的对齐环境。(我需要建议,看看对于这个特定部分什么方法更好)
我正在调整表格大小,因为它溢出了页面,如果有其他方法可以避免这种情况,我愿意接受建议。
表是使用以下代码创建的:
\documentclass[12pt, a4paper]{report}
\usepackage[top=3cm,bottom=2.5cm,right=2.5cm,left=4cm]{geometry}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{times}
\begin{document}
\begin{table}[h]
\centering
\resizebox{\columnwidth}{!}{%
\begin{tabular}{rrrrrl|c|c|c|c|c|c|c|c|c|c| }
\hline
\multicolumn{6}{c}{\textbf{(a) Forma Algebraica}} & \multicolumn{9}{c}{\textbf{(b) Forma Tabular}} \\ \hline
\multicolumn{6}{c|}{} & \multirow{2}{3em}{\textbf{Var. basica}} & \multirow{2}{0.9em}{\textbf{Eq.}} & \multicolumn{6}{c}{\textbf{Coeficiente}} & \multirow{2}{2em}{\textbf{Lado der.}} \\
\multicolumn{6}{c|}{} & & & $Z$ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ \\
\hline
$(0)$ & $Z$ & $-180x_1$ & $-90x_2$ & & $= 0$ & $Z$ & $(0)$ & $Z$ & $-180$ & $-90$ & $0$ & $0$ & $0$ & $0$ \\
\hline
$(1)$ & & $6x_1$ & $+ 8x_2$ & $+ x_3$ & $=48$ & $x_3$ & $(1)$ & $Z$ & $6$ & $8$ & $1$ & $0$ & $0$ & $48$ \\
\hline
$(2)$ & & $x_1$ & & $+ x_4$ & $= 6$ & $x_4$ & $(2)$ & $Z$ & $1$ & $0$ & $0$ & $1$ & $0$ & $6$ \\
\hline
$(3)$ & & & $x_2$ & $+ x_5$ & $= 4$ & $x_5$ & $(3)$ & $0$ & $0$ & $1$ & $1$ & $1$ & $1$ & $4$ \\
\hline
\end{tabular}
}
\caption{Forma tabular.}
\label{tab:simplex_tabular_0}
\end{table}
\end{document}
答案1
编辑:
不太清楚您所说的“是否有可能将绿色框内的方程式作为多行内的对齐环境”。这可以通过多种方式实现:
- 数学行之间有线,参见案例 A
- 我们之前使用过,但没有数学行之间的线,参见案例 B
- 使用
aligned
环境为amsmath
,见案例C
您定义的列多于需要的列。
使用该
makecell
包可以很好地完成多行单元的对齐。我不会使用
scalebox
。宁愿将字体大小减小到\small
案例A:
\documentclass[12pt, a4paper]{report}
\usepackage[hmargin={2.5cm,4cm},
vmargin={3cm,2.5cm}]{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{array, makecell, multirow}
\renewcommand\theadfont{\bfseries\normalsize\linespread{0.8}\selectfont}
\usepackage{times}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\centering
\small
\renewcommand\cellalign{bc}
\setlength\tabcolsep{5pt}
\begin{tabular}{@{} c *{4}{r@{\;}}l|*{8}{c|}c @{}}
\hline
\multicolumn{6}{c}{\textbf{(a) Forma Algebraica}}
& \multicolumn{9}{c}{\textbf{(b) Forma Tabular}} \\
\hline
\multicolumn{6}{c|}{}
& \multirow{2}{*}{\thead{Var.\\ basica}}
& \multirow{2}{*}{\thead{\\Eq.}}
& \multicolumn{6}{c|}{\textbf{Coeficiente}}
& \multirow{2}{*}{\thead{Lado\\ der.}} \\
\cline{9-14}
\multicolumn{6}{c|}{}
& & & $Z$ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ \\
\hline
$(0)$ & $Z$ & $-180x_1$ & $-90x_2$ & & $= 0$ & $Z$ & $(0)$ & $Z$ & $-180$ & $-90$ & $0$ & $0$ & $0$ & $0$ \\
\hline
$(1)$ & & $6x_1$ & $+ 8x_2$ & $+ x_3$ & $=48$ & $x_3$ & $(1)$ & $Z$ & $6$ & $8$ & $1$ & $0$ & $0$ & $48$ \\
\hline
$(2)$ & & $x_1$ & & $+ x_4$ & $= 6$ & $x_4$ & $(2)$ & $Z$ & $1$ & $0$ & $0$ & $1$ & $0$ & $6$ \\
\hline
$(3)$ & & & $x_2$ & $+ x_5$ & $= 4$ & $x_5$ & $(3)$ & $0$ & $0$ & $1$ & $1$ & $1$ & $1$ & $4$ \\
\hline
\end{tabular}
\caption{Forma tabular.}
\label{tab:simplex_tabular_0}
\end{table}
\end{document}
(红线表示页面布局)
- 另一种可能性是使用
tabularray
包。 - 有了它,表格会更美观,并且表格主体的代码会更简单。
\documentclass[12pt, a4paper]{report}
\usepackage[hmargin={2.5cm,4cm},
vmargin={3cm,2.5cm}]{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{times}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\small
\begin{tblr}{hlines, vline{7-Y},
colsep = 4pt,
colspec = {@{} Q[c,mode=math]
Q[c,mode=math, rightsep=1pt]
*{3}{Q[r,mode=math, colsep=1pt]}
*{4}{Q[c,mode=math]}
*{5}{X[c,mode=math]}
c @{}},
row{1,2} = {mode=text, font=\bfseries}
}
\SetCell[c=6]{c} (a) Forma Algebraica
& & & & & & \SetCell[c=9]{c} (b) Forma Tabular
& & & & & & & & \\
\SetCell[c=6, r=2]{c}
& & & & & & \SetCell[r=2]{f} {Var.\\ basica}
& \SetCell[r=2]{f} Eq.
& \SetCell[c=6]{c} Coeficiente
& & & & & & \SetCell[r=2]{f} {Lado\\ der.} \\
& & & & & & & & Z & x_1 & x_2 & x_3 & x_4 & x_5 & \\
(0) & Z & -180x_1 & -90x_2 & & = 0 & Z & (0) & Z & -180 & -90 & 0 & 0 & 0 & 0 \\
(1) & & 6x_1 & + 8x_2 & + x_3 & =48 & x_3 & (1) & Z & 6 & 8 & 1 & 0 & 0 & 48 \\
(2) & & x_1 & & + x_4 & = 6 & x_4 & (2) & Z & 1 & 0 & 0 & 1 & 0 & 6 \\
(3) & & & x_2 & + x_5 & = 4 & x_5 & (3) & 0 & 0 & 1 & 1 & 1 & 1 & 4 \\
\end{tblr}
\caption{Forma tabular.}
\label{tab:simplex_tabular_0}
\end{table}
\end{document}
案例 B:
\documentclass[12pt, a4paper]{report}
\usepackage[hmargin={2.5cm,4cm},
vmargin={3cm,2.5cm}]{geometry}
\usepackage{times}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\begin{document}
\begin{table}[h]
\small
\begin{tblr}{hline{1,2-4,Z}, vline{2,7-Y}={1-Z}{solid},
hline{2,5-Z} = {1,7-Z}{solid},
colsep = 4pt,
colspec = {@{} Q[c,mode=math]
Q[r,mode=math,rightsep=1pt]
*{3}{Q[r,mode=math,colsep=1pt]}
Q[l,mode=math]
*{3}{Q[c,mode=math]}
*{5}{X[c,mode=math]}
c @{}},
row{1,2} = {mode=text, font=\bfseries}
}
\SetCell[c=6]{h} (a) Forma Algebraica
& & & & & & \SetCell[c=9]{c} (b) Forma Tabular
& & & & & & & & \\
\SetCell[c=6, r=2]{c}
& & & & & & \SetCell[r=2]{f} {Var.\\ basica}
& \SetCell[r=2]{f} Eq.
& \SetCell[c=6]{c} Coeficiente
& & & & & & \SetCell[r=2]{f} {Lado\\ der.} \\
& & & & & & & & Z & x_1 & x_2 & x_3 & x_4 & x_5 & \\
(0) & Z & -180x_1 & -90x_2 & & = 0 & Z & (0) & Z & -180 & -90 & 0 & 0 & 0 & 0 \\
(1) & & 6x_1 & + 8x_2 & + x_3 & =48 & x_3 & (1) & Z & 6 & 8 & 1 & 0 & 0 & 48 \\
(2) & & x_1 & & + x_4 & = 6 & x_4 & (2) & Z & 1 & 0 & 0 & 1 & 0 & 6 \\
(3) & & & x_2 & + x_5 & = 4 & x_5 & (3) & 0 & 0 & 1 & 1 & 1 & 1 & 4 \\
\end{tblr}
\caption{Forma tabular.}
\label{tab:simplex_tabular_0}
\end{table}
\end{document}
案例C:
\documentclass[12pt, a4paper]{report}
\usepackage[hmargin={2.5cm,4cm},
vmargin={3cm,2.5cm}]{geometry}
\usepackage{times}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\begin{document}
\begin{table}[h]
\small
\begin{tblr}{hline{1,2-4,Z}, vline{3-Y}={1-Z}{solid},
hline{5-Z} = {3-Z}{solid},
colsep = 4pt,
colspec = {@{}
*{7}{Q[c,mode=math]}
*{4}{X[c,mode=math]}
@{}},
row{1,2} = {mode=text, font=\bfseries}
}
\SetCell[c=2]{c} (a) Forma Algebraica
& & \SetCell[c=9]{c} (b) Forma Tabular
& & & & & & & & \\
\SetCell[c=2,r=2]{c}
& & \SetCell[r=2]{f} {Var.\\ basica}
& \SetCell[r=2]{f} Eq.
& \SetCell[c=6]{c} Coeficiente
& & & & & & \SetCell[r=2]{f} {Lado\\ der.} \\
& & & & Z & x_1 & x_2 & x_3 & x_4 & x_5 & \\
(0) & \SetCell[r=4]{c}
\begin{aligned}
Z - 180x_1 - 90x_2 & = 0\\
6x_1 + 8x_2 + x_3 & = 48\\
x_1 + x_4 & = 6\\
x_2 + x_5 & = 4\\
\end{aligned} & Z & (0) & Z & -180 & -90 & 0 & 0 & 0 & 0 \\
(1) & & x_3 & (1) & Z & 6 & 8 & 1 & 0 & 0 & 48 \\
(2) & & x_4 & (2) & Z & 1 & 0 & 0 & 1 & 0 & 6 \\
(3) & & x_5 & (3) & 0 & 0 & 1 & 1 & 1 & 1 & 4 \\
\end{tblr}
\caption{Forma tabular.}
\label{tab:simplex_tabular_0}
\end{table}
\end{document}
答案2
以下是您可以使用 做的{NiceTabular}
事情nicematrix
。
\documentclass[12pt, a4paper]{report}
\usepackage[top=3cm,bottom=2.5cm,right=2cm,left=2cm]{geometry}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{times}
\usepackage{nicematrix}
\begin{document}
\begin{table}[h]
\centering
\small
\begin{NiceTabular}{rrrrrl|c|c|c|c|c|c|c|c|c}[hlines]
\RowStyle[bold,nb-rows=2]{}
\Block{1-6}{(a) Forma Algebraica} &&&&&& \Block{1-9}{(b) Forma Tabular} \\
\Block[t]{2-6}{} &&&&&& \Block[t]{2-1}{Var.\\ basica} & \Block[t]{2-1}{\textbf{Eq.}} & \Block{1-6}{Coeficiente} &&&&&& \Block{2-1}{Lado\\ der.} \\
& & & &&&&& $Z$ & $x_1$ & $x_2$ & $x_3$ & $x_4$ & $x_5$ \\
$(0)$ & $Z$ & $-180x_1$ & $-90x_2$ & & $= 0$ & $Z$ & $(0)$ & $Z$ & $-180$ & $-90$ & $0$ & $0$ & $0$ & $0$ \\
$(1)$ & & $6x_1$ & $+ 8x_2$ & $+ x_3$ & $=48$ & $x_3$ & $(1)$ & $Z$ & $6$ & $8$ & $1$ & $0$ & $0$ & $48$ \\
$(2)$ & & $x_1$ & & $+ x_4$ & $= 6$ & $x_4$ & $(2)$ & $Z$ & $1$ & $0$ & $0$ & $1$ & $0$ & $6$ \\
$(3)$ & & & $x_2$ & $+ x_5$ & $= 4$ & $x_5$ & $(3)$ & $0$ & $0$ & $1$ & $1$ & $1$ & $1$ & $4$ \\
\end{NiceTabular}
\caption{Forma tabular.}
\label{tab:simplex_tabular_0}
\end{table}
\end{document}