我必须说,我对 TeX 中的表格并不熟悉,而且确实还不了解它们的工作原理。我尝试构建一个表格,代码如下。
\documentclass{article}
\usepackage[table]{xcolor}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{2.5}
\newcolumntype{s}{>{\columncolor[HTML]{7FFFD4}} p{3cm}}
\newcolumntype{d}{>{\columncolor[HTML]{FFC0CB}} p{4cm}}
\arrayrulecolor[HTML]{DB5800}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{ |s|d|}
\hline
\rowcolor{lightgray} \multicolumn{2}{|c|}{Equazione differenziale lineare del primo ordine} \\
\hline
\qquad \quad $b=0$ & \qquad \qquad $b \neq 0$ \\
\hline
\textbf{omogenea}, \textbf{a variabili separabili} & \qquad \textbf{non omogenea}\\
\hline
\end{tabular}
\end{table}
\end{document}
但是,在输出中,我想放大表格的第一个单元格(海蓝宝石色的单元格),以便单词“omogenea, a variabili separabili”位于一行中,而不是像本例中那样被拆分开来。此外,我想找出一种简单的方法将所有命令集中在单元格内。
最佳答案
3
最简单的方法可能是用p{3cm}
来替换c
,它将c
以橡胶宽度输入您的内容。
\documentclass{article}
\usepackage[table]{xcolor}
\setlength{\arrayrulewidth}{1mm}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{2.5}
\newcolumntype{s}{>{\columncolor[HTML]{7FFFD4}} c}
\newcolumntype{d}{>{\columncolor[HTML]{FFC0CB}} c}
\arrayrulecolor[HTML]{DB5800}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ |s|d|}
\hline
\rowcolor{lightgray} \multicolumn{2}{|c|}{Equazione differenziale lineare del primo ordine} \\
\hline
$b=0$ & $b \neq 0$ \\
\hline
\textbf{omogenea}, \textbf{a variabili separabili} & \textbf{non omogenea}\\
\hline
\end{tabular}
\end{table}
\end{document}
编辑:您的[H]
选项table
需要该float
包。但是,我强烈反对使用它。
1
-
1+1。您可能还想提一下,建议的设置不能保证环境的宽度
tabular
不会超过\textwidth
,即文本块的宽度。这对于tabular
当前的环境来说不是问题,但对于其他表来说可能是问题。
–
|
{NiceTabular}
供参考,这里有一种使用创建该表的方法nicematrix
。
\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}
\begin{document}
\begin{table}
\centering
\setlength{\arrayrulewidth}{1mm}
\arrayrulecolor[HTML]{DB5800}
\setlength{\tabcolsep}{18pt}
\renewcommand{\arraystretch}{2.5}
\begin{NiceTabular}{cc}[hvlines]
\CodeBefore
\columncolor[HTML]{7FFFD4}{1}
\columncolor[HTML]{FFC0CB}{2}
\rowcolor{lightgray}{1}
\Body
\Block{1-2}{Equazione differenziale lineare del primo ordine} \\
$b=0$ & $b \neq 0$ \\
\RowStyle{\bfseries}
omogenea, a variabili separabili & non omogenea\\
\end{NiceTabular}
\end{table}
\end{document}
|
类型单元格的单元格宽度p
是参数:p{3cm} 表示单元格宽度为 3cm。您可以通过更改p{3cm}
为c
或使用>{centering}p{6cm}
或类似的东西来使其居中(而不是对齐)。
如果这不能回答您的问题,那么我就不明白您想做什么和/或您期望什么。
顺便说一句,您发布的代码无法编译,但删除[H]
说明符可以解决这个问题。
|
|