你们中有些人可能知道 Phillip Tanedo 的 FlipBeamertheme(http://www.physics.uci.edu/~tanedo/files/code/FlipBeamerTemplate.pdf)
我喜欢它的标题风格。Tanedo 用了一张图片:
这三行文字的两边都经过了调整。我猜 Tanedo 一定花了不少时间调整字体大小、字距和字间距,才做到了这一点。
现在我想知道是否可以使用 xelatex 或 lualatex “自动”实现该效果。
类似于计算所需字体大小然后微调字距的环境。
答案1
具有可调节功能的解决方案:
\documentclass{article}
\usepackage{fontspec}
\usepackage{graphicx}
\usepackage{xparse}
\setsansfont{Gill Sans}
\ExplSyntaxOn
\NewDocumentCommand{\tanedo}{O{}m}
{% do everything in a group not to clobber previous values
\group_begin:
% evaluate the keys in the optional argument
\keys_set:nn { schmendrich/tanedo } { #1 }
% pass control of typesetting to an internal function
\schmendrich_tanedo:n { #2 }
% close the group
\group_end:
}
% define the needed keys
\keys_define:nn { schmendrich/tanedo }
{
width .dim_set:N = \l_schmendrich_title_width_dim,
skip .dim_set:N = \l_schmendrich_title_skip_dim,
skip .initial:n = { 3pt },
font .tl_set:N = \l_schmendrich_title_font_tl
}
% a couple of needed variables
\seq_new:N \l_schmendrich_input_title_seq
\box_new:N \l_schmendrich_line_box
% the main function
\cs_new_protected:Npn \schmendrich_tanedo:n #1
{
% split the title argument into pieces at \\
\seq_set_split:Nnn \l_schmendrich_input_title_seq { \\ } { #1 }
% if no required width has been specified, determine the natural width
% (the signal for this is the width variable is still 0pt
\dim_compare:nT { \l_schmendrich_title_width_dim = 0pt }
{
\seq_map_inline:Nn \l_schmendrich_input_title_seq
{% put the item in a box applying the chosen font
\hbox_set:Nn \l_schmendrich_line_box { \tl_use:N \l_schmendrich_title_font_tl ##1 }
% compare the width of the box with the last stored width value
\dim_compare:nT { \l_schmendrich_title_width_dim < \box_wd:N \l_schmendrich_line_box }
{% if the stored value is less than the current one, set accordingly
\dim_set:Nn \l_schmendrich_title_width_dim { \box_wd:N \l_schmendrich_line_box }
}
}
}
% we do it in a minipage as wide as necessary
\begin{minipage}{\l_schmendrich_title_width_dim}
% some low level trickery
\lineskiplimit=\c_max_dim % two lines will always be too near
\lineskip = \l_schmendrich_title_skip_dim % so \lineskip will be used
% apply \centering (not strictly necessary, though)
\centering
% set the font
\tl_use:N \l_schmendrich_title_font_tl
% typeset each line in a suitable \resizebox
\seq_map_inline:Nn \l_schmendrich_input_title_seq
{
\resizebox{\l_schmendrich_title_width_dim}{!}{##1} \\
}
% finish off
\end{minipage}
}
\ExplSyntaxOff
\begin{document}
\sffamily
\tanedo{THIS IS A \\ SAMPLE \\ TALK TITLE}
\bigskip
\tanedo[font=\bfseries]{THIS IS A \\ SAMPLE \\ TALK TITLE}
\bigskip
\tanedo[width=5cm]{THIS IS A \\ SAMPLE \\ TALK TITLE}
\bigskip
\tanedo[width=5cm,skip=6pt,font=\bfseries]{THIS IS A \\ SAMPLE \\ TALK TITLE}
\end{document}
如果未指定宽度,则将按其自然大小测量线条,并使用最宽的线条来调整其他线条的大小。您还可以调整线条之间的间距(默认为 3pt)并设置字体属性。
每一行都设置为\resizebox
具有适当宽度,通过\seq_map_inline:Nn
处理先前存储的每一行\seq_set_split:Nnn
。
width
当未指定选项时,使用相同的想法来计算自然宽度。
答案2
和adjustbox
。
\documentclass{article}
\usepackage{adjustbox}
\begin{document}
\noindent
\adjustbox{width=15mm,height=1.5ex}{THIS IS A}\\
\adjustbox{width=15mm,height=1.5ex}{SAMPLE}\\
\adjustbox{width=15mm,height=1.5ex}{TALK LITTLE}
\end{document}
这也可以做到\resizebox
。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\noindent
\resizebox{15mm}{1.5ex}{THIS IS A}\\
\resizebox{15mm}{1.5ex}{SAMPLE}\\
\resizebox{15mm}{1.5ex}{TALK LITTLE}
\end{document}