如何建立帶有框架框的頁面佈局?

如何建立帶有框架框的頁面佈局?

對於我正在編寫的報告,我有一個需要包含的頁面的 MS Word 範本。該頁面如下所示(從 Word 列印畫面):

Word 文件的列印畫面

然而,有一些事情讓我不想以目前的形式使用這個模板,而是用 LaTeX 重寫它:

  1. 此頁面使用 Word 編寫,而我的報告的其餘部分使用 LaTeX 編寫。因此樣式會有所不同,例如包括字體和線寬。
  2. 當您包含以 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

只是一些提示,

  1. 使用minipages並使用鍵值介面來輸入資料。當你有 10 分鐘的時間來取得一份遲到的報告表格時,輸入資料會迷失在大量的 LaTeX 指令中,這是令人困惑且容易出錯的。想想minipagesdivs好像你熟悉的html是同一個概念。
  2. 了解你的minipages.您將必須使用命令的完整形式,即滿足外部和內部對齊以及指定框的高度。
  3. 在原型設計時使用fbox,但您可能希望在最終版本中使用規則。
  4. 至少預算 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,您就會得到它。您需要考慮multicolumnmultirow打包才能實現這種格式。

另一個解決方案是檢查巴波斯特用於乳膠海報。創建如此奇怪的佈局是非常優化的。用它來建立一個 PDF 並將其包含在您的 LaTeX 文件中。

答案4

使用浮動元素或小型頁面有一個缺點,Latex 仍然可以改變佈局。這通常是一件好事,但對於必須遵循精確尺寸的形式來說卻並非如此。

我用PGF/Tikz它可以讓您將任何內容準確地放置在頁面上您想要的位置。

儘管這是一種蠻力(我想要!那個!正是!那裡!),但它只創建了您需要的佈局。 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}

在此輸入影像描述

相關內容