对于我正在撰写的报告,我有一个需要包含在其中的页面的 MS Word 模板。该页面如下所示(从 Word 打印屏幕截图):
但是,有几件事让我不想使用当前形式的该模板,而是用 LaTeX 重写它:
- 此页是用 Word 编写的,而我的报告的其余部分是用 LaTeX 编写的。因此样式会有所不同,例如字体和线宽。
- 当您包含以 pdf 格式存储的矢量图像时,Word 会将其转换为低分辨率的光栅图像(是的,在您将其打印为 pdf 文件后,它仍然会被光栅化)。
不管怎样,关于使用 LaTeX 的争论已经足够了,现在来回答这个问题:我如何使用 LaTeX 实现这种布局? 目前我需要知道的是如何创建这种以这种模式彼此相邻的框,以及如何在框内正确调整文本。
编辑:如果框的尺寸与框内的内容无关,那就太好了。这样,对于使用相同 LaTeX 模板的不同人来说,布局将保持不变。我所在大学的系可能会将其用作 Word 模板的官方替代品。
答案1
我在我的报告中这样做。首先,您需要在类或样式文件中进行设置。在我的例子中,它是我们的报告类,它包含以下用于制作政府 SF-298 表格的定义:
\newenvironment{createSFtwoNINEeight}{
\clearpage
\begin{singlespace}
\begin{picture}(612,650)(70,82)
\includegraphics{SF298}
\footnotesize
\@SFitemONE{\@pubdate}
\@SFitemTWO{Final}
\@SFitemEIGHT{\@arlrptno}
\@SFitemTWELVE{\@distribution}
\def\SFitemSIXTEENaVALUE{Unclassified}
\def\SFitemSIXTEENbVALUE{Unclassified}
\def\SFitemSIXTEENcVALUE{Unclassified}
}{
\put(-564,100){\parbox[c]{0.8in}{\centering
\SFitemSIXTEENaVALUE}}
\put(-493,100){\parbox[c]{0.8in}{\centering
\SFitemSIXTEENbVALUE}}
\put(-422,100){\parbox[c]{0.8in}{\centering
\SFitemSIXTEENcVALUE}}
\normalsize
\end{picture}
\end{singlespace}
}
\newcommand\@SFitemONE[1]{\put(-564,662){#1}}
\newcommand\@SFitemTWO[1]{\put(-424,662){#1}}
\newcommand\SFitemTHREE[1]{\put(-217,662){#1}}
\newcommand\SFitemFOUR[1]{\put(-564,636){\parbox[t]{4.65in}{\raggedright#1}}}
\newcommand\SFitemFIVEa[1]{\put(-217,636){#1}}
\newcommand\SFitemFIVEd[1]{\put(-217,569){#1}}
\newcommand\SFitemSIX[1]{\put(-564,569){\parbox[t]{4.65in}{#1}}}
\newcommand\SFitemSEVEN[1]{\put(-564,485){\parbox[c]{4.65in}{\raggedright#1}}}
\newcommand\@SFitemEIGHT[1]{\put(-217,485){#1}}
\newcommand\SFitemNINE[1]{\put(-564,432){\parbox[c]{4.65in}{\raggedright#1}}}
\newcommand\SFitemTEN[1]{\put(-217,445){#1}}
\newcommand\SFitemELEVEN[1]{\put(-217,412){#1}}
\newcommand\@SFitemTWELVE[1]
{\put(-564,381){\parbox[c]{7.15in}{\setstretch{0.9}#1}}}
\newcommand\SFitemTHIRTEEN[1]{\put(-564,350){\parbox[t]{7.1in}{\raggedright#1}}}
\newcommand\SFitemFOURTEEN[1]{\put(-564,310){\parbox[t]{7.1in}{\raggedright#1}}}
\newcommand\SFitemFIFTEEN[1]{\put(-564,148){\parbox[b]{7.1in}{\raggedright#1}}}
\newcommand\SFitemSIXTEENa[1]{\def\SFitemSIXTEENaVALUE{#1}}
\newcommand\SFitemSIXTEENb[1]{\def\SFitemSIXTEENbVALUE{#1}}
\newcommand\SFitemSIXTEENc[1]{\def\SFitemSIXTEENcVALUE{#1}}
\newcommand\SFitemSEVENTEEN[1]{
\put(-352,108){\parbox[c]{0.8in}{\centering#1}}
}
\newcommand\SFitemEIGHTEEN[1]{\put(-285,108){\parbox[c]{0.8in}{\centering#1}}}
\newcommand\SFitemNINETEENa[1]{\put(-217,124){#1}}
\newcommand\SFitemNINETEENb[1]{\put(-217,100){#1}}
如您所见,它使用 LaTeX 的原生图片环境,在该环境中,它将文本覆盖在空白表单之上(空白表单作为图形导入)。然后,您需要在文档中调用环境来绘制图片:
%% OPTION I: CREATE YOUR OWN SF298 in LaTeX:
\begin{createSFtwoNINEeight}
% SFitemONE AUTOMATICALLY FILLED IN (\pubdate)
% SFitemTWO AUTOMATICALLY FILLED IN (Final)
\SFitemTHREE{January 2011-October 2011}
\SFitemFOUR{Frontiers in Anisotropic Shock-Wave Modeling}
\SFitemFIVEd{AH80}
\SFitemSIX{Alexander A. Lukyanov\\Steven B. Segletes}
\SFitemSEVEN{Abingdon [EDITED OUT]}
% SFitemEIGHT AUTOMATICALLY FILLED IN (\arlrptno)
% \SFitemNINE{As needed...}
% SFitemTWELVE AUTOMATICALLY FILLED IN (\distribution)
\SFitemTHIRTEEN{[EDITED OUT].}
\SFitemFOURTEEN{
Studies of anisotropic materials and the discovery of various novel and
unexpected phenomena under shock loading has contributed significantly
to our understanding of the behavior of condensed matter. The variety of
experimental studies for isotropic materials displays systematic
patterns, giving basic insights into the underlying physics of
anisotropic shock-wave modeling. There are many similarities and
significant differences in the phenomena observed for isotropic and
anisotropic materials under shock-wave loading. Despite this, the
anisotropic constitutive equations must represent, mathematically and
physically, the generalization of the conventional constitutive equations for
isotropic material and reduce to the conventional constitutive equations
in the limit of isotropy. This report presents the current state of the
art in the experimental and theoretical developments of this fascinating
field.
}
\SFitemFIFTEEN{anisotropic material, anisotropic
plasticity, shock waves, equation of state, stress decomposition}
% \SFitemSIXTEENa defaults to UNCLASSSIFIED
% \SFitemSIXTEENb defaults to UNCLASSSIFIED
% \SFitemSIXTEENc defaults to UNCLASSSIFIED
\SFitemSEVENTEEN{UU}
\SFitemEIGHTEEN{72}% = FRONT MATTER PP. + REPORT PP. + 2
\SFitemNINETEENa{Steven B. Segletes}
\SFitemNINETEENb{[EDITED OUT]}
\end{createSFtwoNINEeight}
最终结果是
为了响应要求提供独立示例的请求,我截取了本页顶部的提问者图片并将其保存(作为 form.png)。然后我写了这个简短的片段
\documentclass{article}
\usepackage{graphicx}
\usepackage{setspace}
\newenvironment{myForm}{
\clearpage
\begin{singlespace}
\begin{picture}(600,500)(70,82)
\includegraphics[height=9in]{form}
\footnotesize
\SFitemONE{\pubdate}
\SFitemEIGHT{\rptno}
}{
\normalsize
\end{picture}
\end{singlespace}
}
\newcommand\SFitemONE[1]{\put(-138,585){#1}}
\newcommand\SFitemEIGHT[1]{\put(-410,500){\textbf{#1}}}
\newcommand\SFitemSEVENTEEN[1]{
\put(-400,270){\parbox[c]{4.8in}{#1}}
}
\begin{document}
\def\pubdate{\today}
\def\rptno{xyz-123}
\begin{myForm}
\SFitemSEVENTEEN{This is the extended text This is the extended text
This is the extended text This is the extended text This is the
extended text This is the extended text This is the extended text }
\end{myForm}
\end{document}
结果如下,其中报告编号、日期和扩展文本部分已添加到用户表单中。在此示例中,我使用环境添加数据(\SFitemSEVENTEEN
)以及在表单中使用先前定义的数据(\pubdate
和)\rptno
答案2
一些小建议,
- 使用
minipages
键值接口来输入数据。当您有 10 分钟的时间来为迟到的报告填写表格,而这份报告却淹没在大量 LaTeX 命令中时,输入数据会让人感到困惑,而且容易出错。想象minipages
一下divs
,您熟悉的html
是同一个概念。 - 了解你的
minipages
。你必须使用命令的完整形式,即满足外部和内部对齐以及指定框的高度。 - 在原型设计时使用
fbox
,但您可能希望在最终版本中使用规则。 - 至少要花 1-2 个小时才能得到完美的表格。如果你熟悉 TikZ,它也可以成为你的朋友。以防有人要求圆角。
我通常将其用作PGF
钥匙。这是 MWE
\documentclass{article}
\usepackage{pgf}
\newcommand\setform{\pgfqkeys{/form }}
\setform{field1/.store in=\fieldi,
field2/.store in=\fieldii,
}
\begin{document}
\newcommand\myform{%
\fboxrule=0.4pt
\fbox{\begin{minipage}{\textwidth}
\fbox{\begin{minipage}[t][3cm][t]{0.25\textwidth}
\textbf{Name} \fieldi
\end{minipage}}%
\fbox{\begin{minipage}[t][3cm][t]{0.4\textwidth}
\textbf{Subject} \fieldii
\end{minipage}}
\fbox{\begin{minipage}[t][3cm][t]{0.25\textwidth}
test
\end{minipage}}
\end{minipage}}
}
\setform{field1 = G. Wales,
field2 = Mathematics}
\myform
\end{document}
答案3
使用table
环境与列中的环境组合minipage
即可获得。您需要考虑multicolumn
和multirow
包来实现此格式。
另一个解决方案是检查巴波斯特适用于 LaTeX 海报。它非常适合创建这种奇怪的布局。使用它创建 PDF 并将其包含在 LaTeX 文档中。
答案4
使用浮动元素或迷你页面的缺点是 Latex 仍然可以改变布局。这通常是件好事,但对于必须遵循精确尺寸的表单来说就不是了。
我用PGF/Tikz它可以让你把任何内容放在页面上你想要的任意位置。
尽管这是一种蛮力(我想要 !that! 正是 !there!),但它会创建您需要的布局。Latex 样式完全保留,并且所有宏均可访问。
节点的选项是无限的,所以我在这里只添加了最基本的节点。插入图形同样容易。
\documentclass[a4paper]{article}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\node at (current page.south west){%
\begin{tikzpicture}[remember picture, overlay]
\draw (25mm,250mm) node [draw, anchor = south west, text width = 10 cm, minimum height = 3 cm]
{Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum } ;
\draw (135mm,250mm) node [draw, anchor = south west, text width = 3 cm, minimum height = 3 cm] {};
\end{tikzpicture}
};
\end{tikzpicture}
\end{document}