我正在尝试使用包中的运算符对\scalebox
某一列中的每个单元格进行申请。>{...}
<{...}
array
以下是我尝试让它发挥作用
\documentclass{article}
\usepackage{array}
\usepackage{graphics}
\begin{document}
\begin{tabular}{cc>{\scalebox{1.5}\bgroup}c<{\egroup}}
some & simple & text
\end{tabular}
\end{document}
请注意,我不是在寻找建议使用\large
或 的解决方案\fontsize{...}
。我需要的正是\scalebox
make 才能工作。
答案1
除了使用 lrbox 环境的“简单”解决方案之外......
%! TEX program = lualatex
\documentclass{article}
\usepackage{array}
\usepackage{graphics}
\begin{document}
\newsavebox{\mybox}
\begin{tabular}{cc>{\begin{lrbox}{\mybox}}c<{\end{lrbox}%
\scalebox{1.5}{\usebox{\mybox}}%
}}
some & simple & te \verb+x\+ t
\end{tabular}
\end{document}
还有调整 scalebox 实现的解决方案(问题很明显——一旦 graphicx 包更改宏定义,您的代码可能会中断/不兼容)
%! TEX program = lualatex
\documentclass{article}
\usepackage{array}
\usepackage{graphics}
\begin{document}
\makeatletter
% scalebox is defined as:
% \protected macro:#1->\@ifnextchar [{\Gscale@box {#1}}{\Gscale@box {#1}[#1]}
% so \scalebox{factor}{content} = \Gscale@box{factor}[factor]{content}
% \Gscale@box body is
% \leavevmode \def \Gscale@x {#1}\def \Gscale@y {#2}\setbox \z@ \hbox {{#3}}\setbox \tw@ \hbox {\Gscale@start \rlap {\copy \z@ }\Gscale@end }\ifdim #2\p@ <\z@ \ht \tw@ -#2\dp \z@ \dp \tw@ -#2\ht \z@ \else \ht \tw@ #2\ht \z@ \dp \tw@ #2\dp \z@ \fi \ifdim #1\p@ <\z@ \hb@xt@ -#1\wd \z@ {\kern -#1\wd \z@ \box \tw@ \hss }\else \hb@xt@ #1\wd \z@ {\box \tw@ \kern #1\wd \z@ \hss }\fi %
% take the part before #3 put into Gscaleboxfirst, and the part after that put in Gscaleboxsecond.
\def\Gscaleboxfirst #1#2{%
\leavevmode \def \Gscale@x {#1}\def \Gscale@y {#2}\setbox \z@ \hbox \bgroup\bgroup%
}
\def\Gscaleboxsecond #1#2{%
\egroup\egroup \setbox \tw@ \hbox {\Gscale@start \rlap {\copy \z@ }\Gscale@end }\ifdim #2\p@ <\z@ \ht \tw@ -#2\dp \z@ \dp \tw@ -#2\ht \z@ \else \ht \tw@ #2\ht \z@ \dp \tw@ #2\dp \z@ \fi \ifdim #1\p@ <\z@ \hb@xt@ -#1\wd \z@ {\kern -#1\wd \z@ \box \tw@ \hss }\else \hb@xt@ #1\wd \z@ {\box \tw@ \kern #1\wd \z@ \hss }\fi %
}
\makeatother
\newsavebox{\mybox}
\begin{tabular}{cc>{\Gscaleboxfirst{1.5}{1.5}}c<{\Gscaleboxsecond{1.5}{1.5}}}
some & simple & te \verb+x\+ t
\end{tabular}
\end{document}
阅读代码注释以了解代码的来源。解析可选参数/避免在第一部分和第二部分中重复参数留给读者练习。
与 collcell 不同,这两者都支持逐字翻译(并不是说非装箱解决方案不能支持逐字翻译,只是使用 set catcode 和 scantokens/input 来支持逐字翻译更麻烦)
谈到逐字逐句,我还要提到我的包cprotectinside
(允许\verb
和其他类似逐字逐句的命令/环境与解决方案一起使用collcell
)......
%! TEX program = lualatex
\documentclass{article}
\usepackage{array}
\usepackage{graphics}
\usepackage{collcell}
\usepackage{cprotectinside}
\newcommand{\myresize}[1]{\scalebox{1.5}{#1}}
\begin{document}
\cprotectinside{*}{
\begin{tabular}{cc>{\collectcell\myresize}c<{\endcollectcell}}
some & simple & *te\verb+x\+t*
\end{tabular}
}
\end{document}