我有一张表使用tabularx
:
如您所见,行高不一致。我希望每行的高度都与第三行相同(无生命 | 无变化)。
我试过了[1ex]
,但没有任何变化,即使使用例如,[0.1ex]
任何建议都值得赞赏。这是我的表格序言和代码:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}
\usepackage[T1, T2A]{fontenc}
\usepackage{array}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{light-gray}{gray}{0.95}
\renewcommand{\arraystretch}{1}
\title{Lorem}
\author{Ipsum}
\date{\today}
\usepackage{natbib}
\usepackage{graphicx}
\begin{document}
\noindent\begin{tabularx}{1\linewidth} {
| >{\centering\arraybackslash}X
| >{\centering\arraybackslash}X | }
\hline
Ending / Description& How to Decline \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Masculine} \\
\hline
inanimate & no change \\
\hline
animate, a consonant & \selectlanguage{russian}+а\selectlanguage{english} \\
\hline
animate, \selectlanguage{russian}й\selectlanguage{english} & \selectlanguage{russian}-й, +я\selectlanguage{english} \\
\hline
animate, \selectlanguage{russian}ь\selectlanguage{english} & \selectlanguage{russian}-ь, +я\selectlanguage{english} \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Feminine} \\
\hline
\selectlanguage{russian}а\selectlanguage{english} & \selectlanguage{russian}-а, +у\selectlanguage{english} \\
\hline
\selectlanguage{russian}я\selectlanguage{english} & \selectlanguage{russian}-я, +ю\selectlanguage{english} \\
\hline
\selectlanguage{russian}ь\selectlanguage{english} & no change \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Neuter} \\
\hline
all nouns & no change \\
\hline
\end{tabularx}
答案1
使用常规tabular
和包w
中的列类型,您可以获得以下输出。我还通过array
使用以下代码稍微缩短了代码:\foreignlanguage{russian}{...}
\selectlanguage{russian}...\selectlanguage{english}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}
\usepackage[T1, T2A]{fontenc}
\usepackage{array}
\usepackage[table]{xcolor}
\definecolor{light-gray}{gray}{0.95}
\renewcommand{\arraystretch}{1}
\title{Lorem}
\author{Ipsum}
\date{\today}
\begin{document}
\noindent\begin{tabular}{
| wc{\dimexpr0.5\textwidth-2\tabcolsep-1.5\arrayrulewidth}
| >{\selectlanguage{russian}} wc{\dimexpr0.5\textwidth-2\tabcolsep-1.5\arrayrulewidth}<{\selectlanguage{english}} | }
\hline
Ending / Description & \selectlanguage{english}How to Decline \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Masculine} \\
\hline
inanimate & \selectlanguage{english}no change \\
\hline
animate, a consonant & +а \\
\hline
animate, \foreignlanguage{russian}{й} & -й, +я \\
\hline
animate, \foreignlanguage{russian}{ь} & -ь, +я \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Feminine} \\
\hline
\foreignlanguage{russian}{а} & -а, +у \\
\hline
\foreignlanguage{russian}{я} & -я, +ю \\
\hline
\foreignlanguage{russian}{ь} & \selectlanguage{english} no change \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Neuter} \\
\hline
all nouns & no change \\
\hline
\end{tabular}
\end{document}
答案2
您可以切换到 XeLaTeX 或 LuaLaTeX,您可以加载fontspec
包并省去表中的所有指令\foreignlanguage
。\selectlanguage
%% to compile with either XeLaTeX or LuaLaTeX
\documentclass{article}
\usepackage[russian, english]{babel}
\usepackage{fontspec}
\setmainfont{New Computer Modern}
%%\usepackage{array}
\usepackage{tabularx} % 'tabularx' loads 'array' automatically
\newcolumntype{C}{>{\centering\arraybackslash}X}
\usepackage[table]{xcolor}
\definecolor{light-gray}{gray}{0.95}
%%\renewcommand{\arraystretch}{1} % '1' is the default
\begin{document}
\setlength\extrarowheight{2pt} % for a slightly more open "look"
\noindent
\begin{tabularx}{1\linewidth} { | C | C | }
\hline
Ending / Description & How to Decline \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Masculine} \\
\hline
inanimate & no change \\
\hline
animate, a consonant & +а \\
\hline
animate, й & -й, +я \\
\hline
animate, ь & -ь, +я \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Feminine} \\
\hline
а & -а, +у \\
\hline
я & -я, +ю \\
\hline
ь & no change \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Neuter} \\
\hline
all nouns & no change \\
\hline
\end{tabularx}
\end{document}
答案3
原因是存在\selectlanguage{russian}
,因为这个命令应该总是之间段落和列的开始X
位置不正确。请\foreignlanguage
按如下所示替换。
很少使用显式\selectlanguage
:我可以想象它只在不同语言的文档部分中使用。环境otherlanguage
和与用于插入一小段文本otherlanguage*
一起使用更有用。\foreignlanguage
顺便说一下,表格单元格形成组,所以不需要使用\selectlanguage{english}
。
请注意,最后声明的编码是默认编码,因此如果默认语言是英语,那么 T1 应该放在最后。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}
\usepackage[T2A, T1]{fontenc}
\usepackage{array}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{light-gray}{gray}{0.95}
\renewcommand{\arraystretch}{1}
\title{Lorem}
\author{Ipsum}
\date{\today}
\usepackage{natbib}
\usepackage{graphicx}
\begin{document}
\noindent\begin{tabularx}{1\linewidth} {
| >{\centering\arraybackslash}X
| >{\centering\arraybackslash}X | }
\hline
Ending / Description& How to Decline \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Masculine} \\
\hline
inanimate & no change \\
\hline
animate, a consonant & \foreignlanguage{russian}{+а} \\
\hline
animate, \foreignlanguage{russian}{й} & \foreignlanguage{russian}{-й, +я} \\
\hline
animate, \foreignlanguage{russian}{ь} & \foreignlanguage{russian}{-ь, +я} \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Feminine} \\
\hline
\foreignlanguage{russian}{а} & \foreignlanguage{russian}{-а, +у} \\
\hline
\foreignlanguage{russian}{я} & \foreignlanguage{russian}{-я, +ю} \\
\hline
\foreignlanguage{russian}{ь} & no change \\
\hline
\rowcolor{light-gray} \multicolumn{2}{|c|}{Neuter} \\
\hline
all nouns & no change \\
\hline
\end{tabularx}
\end{document}
您可能会考虑为您的表格采用不同的布局。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}
\usepackage[T2A, T1]{fontenc}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ @{\qquad} l c @{} }
\toprule
\multicolumn{1}{@{}l}{Ending/Description} & How to Decline \\
\midrule
\multicolumn{2}{@{}l@{}}{\itshape Masculine} \\
inanimate & no change \\
animate, a consonant & \foreignlanguage{russian}{+а} \\
animate, \foreignlanguage{russian}{й} & \foreignlanguage{russian}{-й, +я} \\
animate, \foreignlanguage{russian}{ь} & \foreignlanguage{russian}{-ь, +я} \\
\midrule
\multicolumn{2}{@{}l@{}}{\itshape Feminine} \\
\foreignlanguage{russian}{а} & \foreignlanguage{russian}{-а, +у} \\
\foreignlanguage{russian}{я} & \foreignlanguage{russian}{-я, +ю} \\
\foreignlanguage{russian}{ь} & no change \\
\midrule
\multicolumn{2}{@{}l@{}}{\itshape Neuter} \\
all nouns & no change \\
\bottomrule
\end{tabular}
\end{document}