![表格内的文本宽度](https://linux22.com/image/450357/%E8%A1%A8%E6%A0%BC%E5%86%85%E7%9A%84%E6%96%87%E6%9C%AC%E5%AE%BD%E5%BA%A6.png)
我正在使用表格来格式化一本书的页面,每页有 6 个棋子位置。我希望位置对齐,如果文本较短,它就可以正常工作,但对于我有较长移动序列的位置,它会影响表格对齐。我想要做的是设置文本的最大宽度,这样它就会自动转到新行而不会破坏水平间距,但我尝试过的文本宽度设置似乎不适用于表格内部。
好页面(板对齐):
坏页(较长的序列破坏了对齐):
代码示例:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{skak}
\usepackage{chessboard}
\usepackage{makecell}
\begin{document}
\begin{center}
\begin{tabular}{cc}
\makecell{
\textbf{ Analysis Position } 2014\\
\textbf{ 1 }\chessboard[setfen= r1bqkb1r/pp3ppp/2n1pn2/2pp2B1/3P4/2P1PN2/PP1N1PPP/R2QKB1R b KQkq - 0 6, smallboard, showmover]\\
\textbf{ 6...c4 }
}
\makecell{
\textbf{ Uesugi - Perelshteyn } 2009\\
\textbf{ 2 }\chessboard[setfen= r1r3k1/qp3pbp/p2p1np1/3Pp3/NP2P3/P2Q1BPP/5P2/R4RK1 w - - 0 19, smallboard, showmover]\\
\textbf{ 19. g4 }
}
\vspace{0.25cm}
\\
\makecell{
\textbf{ Perelshteyn - Onischuk } 2010\\
\textbf{ 3 }\chessboard[setfen= r1bqk2r/pp4bp/2pp2p1/5pP1/2P2Nn1/2N1P3/PPQ2PP1/2KR1B1R w kq - 0 13, smallboard, showmover]\\
\textbf{ 13. c5 d5 14. Ncxd5 cxd5 }
}
\makecell{
\textbf{ Spassky - Petrosian } 1966\\
\textbf{ 4 }\chessboard[setfen= 2kr3r/pbqnbp2/1p2p3/2ppP2p/PP3B1p/2PBPN2/5PP1/R2Q1RK1 b - - 0 17, smallboard, showmover]\\
\textbf{ 17...c4 18. Be2 a6 }
}
\vspace{0.25cm}
\\
\makecell{
\textbf{ Yang - Perelshteyn } 2010\\
\textbf{ 5 }\chessboard[setfen= rnbq1rk1/5pbp/p2p1np1/2p5/1p1PP1P1/4BP2/PP1QN2P/R2NKB1R w KQ - 0 13, smallboard, showmover]\\
\textbf{ 13. dxc5 dxc5 14. Qxd8 Rxd8 15. Bxc5 }
}
\makecell{
\textbf{ Carlsen - Amonatov } 2018\\
\textbf{ 6 }\chessboard[setfen= 1qr1rn2/1b1n1pbk/pBp3pp/Pp2p3/1PP1P3/3B1NNP/5PP1/R1QR2K1 w - - 0 24, smallboard, showmover]\\
\textbf{ 24. c5 }
}
\end{tabular}
\newpage
答案1
我建议使用具有六个参数的宏\twoboards
:标题、板、左图像的移动和标题、板、右图像的移动。
我们不需要任何表格环境。每个\twoboards
都有\centerline
两个对象\singleboad
。这些对象的宽度固定为 120pt,它们之间用 分隔\hss\hss
。因为\centerline
这样,\hbox to\hsize{\hss #1\hss}
我们将第一个对象\singeboard
放在左半部分的中心\hsize
,将第二个对象放在右半部分的中心。
每个\singleboard
都是\vtop
,因此它们按第一行(即按标题)垂直对齐。 的内部参数\vtop
为:\hsize=120pt
和\leftskip
,\rightskip
以便将最后一段移动到给定的 的中心\hsize
。
\def\twoboards#1#2#3#4#5#6{\par
\centerline{\singleboard{#1}{#2}{#3}\hss\hss \singleboard{#4}{#5}{#6}}
\bigskip
}
\def\singleboard#1#2#3{%
\vtop{\hsize=120pt \leftskip=0pt plus1fil \rightskip=\leftskip \parfillskip=0pt
\centerline{\bf\ignorespaces #1\unskip}
\vskip-8pt
\centerline{\ignorespaces #2\unskip}
\noindent\bf \ignorespaces #3\par}%
}
\twoboards
{ Analysis Position 2014 }
{ 1 \chessboard[setfen= r1bqkb1r/pp3ppp/2n1pn2/2pp2B1/3P4/2P1PN2/PP1N1PPP/R2QKB1R b KQkq - 0 6, smallboard, showmover] }
{ 6...c4 }
%
{ Uesugi - Perelshteyn 200 }
{ 2 \chessboard[setfen= r1r3k1/qp3pbp/p2p1np1/3Pp3/NP2P3/P2Q1BPP/5P2/R4RK1 w - - 0 19, smallboard, showmover] }
{ 19. g4 }
\twoboards
{ Perelshteyn - Onischuk 2010 }
{ 3 \chessboard[setfen= r1bqk2r/pp4bp/2pp2p1/5pP1/2P2Nn1/2N1P3/PPQ2PP1/2KR1B1R w kq - 0 13, smallboard, showmover] }
{ 13. c5 d5 14. Ncxd5 cxd5 }
%
{ Spassky - Petrosian 1966 }
{ 4 \chessboard[setfen= 2kr3r/pbqnbp2/1p2p3/2ppP2p/PP3B1p/2PBPN2/5PP1/R2Q1RK1 b - - 0 17, smallboard, showmover] }
{ 17...c4 18. Be2 a6 }
\twoboards
{ Yang - Perelshteyn 2010 }
{ 5 \chessboard[setfen= rnbq1rk1/5pbp/p2p1np1/2p5/1p1PP1P1/4BP2/PP1QN2P/R2NKB1R w KQ - 0 13, smallboard, showmover] }
{ 13. dxc5 dxc5 14.~Qxd8 Rxd8 15. Bxc5 }
%
{ Carlsen - Amonatov 2018 }
{ 6 \chessboard[setfen= 1qr1rn2/1b1n1pbk/pBp3pp/Pp2p3/1PP1P3/3B1NNP/5PP1/R1QR2K1 w - - 0 24, smallboard, showmover] }
{ 24. c5 }
要理解这个解决方案,我们需要知道的一切是 TeX 原始命令\hbox
、、和TeX 原始寄存器、以及所有格式中共同定义的宏。\vtop
\hss
\vskip
\hsize
\leftskip
\rightskip
\centerline
答案2
您没有正确设置tabular
和margins
。我定义了一种具有固定宽度和居中对齐的新列类型P
。我将边距设置为 2cm(顶部、底部、左侧和右侧),并使用showframe
包显示页面框架。您的内容现在位于页面的中心。如果任何单元格的内容较长,它将可拆分并居中对齐。
\documentclass{article}
\usepackage[margin=2cm]{geometry}
\usepackage{showframe}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{skak}
\usepackage{chessboard}
\usepackage{makecell}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\null\vfill{\centering
\begin{tabular}{cc}
\makecell[{{P{6cm}}}]{
\textbf{ Analysis Position } 2014\\
\textbf{ 1 }\chessboard[setfen= r1bqkb1r/pp3ppp/2n1pn2/2pp2B1/3P4/2P1PN2/PP1N1PPP/R2QKB1R b KQkq - 0 6, smallboard, showmover]\\
\textbf{ 6...c4 }
}&
\makecell[{{P{6cm}}}]{
\textbf{ Uesugi - Perelshteyn } 2009\\
\textbf{ 2 }\chessboard[setfen= r1r3k1/qp3pbp/p2p1np1/3Pp3/NP2P3/P2Q1BPP/5P2/R4RK1 w - - 0 19, smallboard, showmover]\\
\textbf{ 19. g4 }
}\vspace{0.25cm}\\
\makecell[{{P{6cm}}}]{
\textbf{ Perelshteyn - Onischuk } 2010\\
\textbf{ 3 }\chessboard[setfen= r1bqk2r/pp4bp/2pp2p1/5pP1/2P2Nn1/2N1P3/PPQ2PP1/2KR1B1R w kq - 0 13, smallboard, showmover]\\
\textbf{ 13. c5 d5 14. Ncxd5 cxd5 }
}&
\makecell[{{P{6cm}}}]{
\textbf{ Spassky - Petrosian } 1966\\
\textbf{ 4 }\chessboard[setfen= 2kr3r/pbqnbp2/1p2p3/2ppP2p/PP3B1p/2PBPN2/5PP1/R2Q1RK1 b - - 0 17, smallboard, showmover]\\
\textbf{ 17...c4 18. Be2 a6 }
}\vspace{0.25cm}\\
\makecell[{{P{6cm}}}]{
\textbf{ Yang - Perelshteyn } 2010\\
\textbf{ 5 }\chessboard[setfen= rnbq1rk1/5pbp/p2p1np1/2p5/1p1PP1P1/4BP2/PP1QN2P/R2NKB1R w KQ - 0 13, smallboard, showmover]\\
\textbf{ 13. dxc5 dxc5 14. Qxd8 Rxd8 15. Bxc5 sdfsdfsdfs}
}&
\makecell[{{P{6cm}}}]{
\textbf{ Carlsen - Amonatov } 2018\\
\textbf{ 6 }\chessboard[setfen= 1qr1rn2/1b1n1pbk/pBp3pp/Pp2p3/1PP1P3/3B1NNP/5PP1/R1QR2K1 w - - 0 24, smallboard, showmover]\\
\textbf{ 24. c5 }
}
\end{tabular}\par}\vfill
\end{document}
输出:
答案3
通过使用表格的两列,您可以更好地控制棋盘的布局和对齐。(并减少打字)
每个游戏有三行:标题、棋盘和走法。
中心和粗体都在列的定义中。添加了一个可选的新命令 \moves
,以保持移动的宽度接近棋盘的宽度(定义为 15*8pt skak
),如果需要的话。
请注意~
最后一行使用的,14.~Qxd8
以避免行中出现孤独的数字。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{skak}
\usepackage{chessboard}
%************************************ added
\usepackage{array}
\newcolumntype{C}{@{}>{\centering\bfseries\arraybackslash}p{0.5\linewidth}@{}}
\newcommand{\moves}[1]{% set the width of moves close to the chessboard 120pt
\parbox[t]{120pt}{\centering #1}
}
%************************************
\begin{document}
\centering
\begin{tabular}{CC}
Analysis Position 2014 & Uesugi - Perelshteyn 2009\\[-0.3cm]
1 \chessboard[setfen= r1bqkb1r/pp3ppp/2n1pn2/2pp2B1/3P4/2P1PN2/PP1N1PPP/R2QKB1R b KQkq - 0 6, smallboard, showmover]&
2 \chessboard[setfen= r1r3k1/qp3pbp/p2p1np1/3Pp3/NP2P3/P2Q1BPP/5P2/R4RK1 w - - 0 19, smallboard, showmover] \\
\moves{ 6...c4 } & \moves{ 19. g4 }\\[0.50cm]% add vertical space
Perelshteyn - Onischuk 2010 & Spassky - Petrosian 1966\\[-0.3cm]
3 \chessboard[setfen= r1bqk2r/pp4bp/2pp2p1/5pP1/2P2Nn1/2N1P3/PPQ2PP1/2KR1B1R w kq - 0 13, smallboard, showmover]&
4 \chessboard[setfen= 2kr3r/pbqnbp2/1p2p3/2ppP2p/PP3B1p/2PBPN2/5PP1/R2Q1RK1 b - - 0 17, smallboard, showmover] \\
\moves{ 13. c5 d5 14. Ncxd5 cxd5 } & \moves{ 17...c4 18. Be2 a6 }\\[0.70cm]% add vertical space
Yang - Perelshteyn 2010 & Carlsen - Amonatov 2018\\[-0.3cm]
5 \chessboard[setfen= rnbq1rk1/5pbp/p2p1np1/2p5/1p1PP1P1/4BP2/PP1QN2P/R2NKB1R w KQ - 0 13, smallboard, showmover]&
6 \chessboard[setfen= 1qr1rn2/1b1n1pbk/pBp3pp/Pp2p3/1PP1P3/3B1NNP/5PP1/R1QR2K1 w - - 0 24, smallboard, showmover]\\
\moves{ 13. dxc5 dxc5 14.~Qxd8 Rxd8 15. Bxc5} & \moves{ 24. c5 }
\end{tabular}