如何包含乳胶文档作为布局示例?

如何包含乳胶文档作为布局示例?

我想将一个乳胶文档包含在另一个乳胶文档中作为图,以提供布局的示例,这意味着,结果乳胶文档应该显示为其他文档中的小页面:

This is a Title of my Main Document

This is some text in the document that talks about a layout and so on an   
refers to a figure that should illustrate this talking (fig. 1). 
    +-------------------------+
    |                         |
    |   This is a latex       |
    |   document, embedded    |
    |   to the main document  |
    |                         |
    |                         |
    |                         |
    |                         |
    |                         |
    |                         |
    |                         |
    +-------------------------+
     fig. 1

这可能吗?

答案1

您在评论中询问是否可以避免单独的文件,但更准确的做法是将文档排版为单独的文件并将结果页面包含在包\includegraphicsgraphicx

显然,对于单个\textbf{hello}甚至枚举环境等小部分,可以将演示的代码放在一个小页面中,但通常很难将外部文档的样式设置与示例隔离开来。

对于包含数十个此类示例的 LaTeX 配套书,源代码示例文档位于主文件中,并逐字写入单独的文件,控制该过程的 makefile 确保这些生成文件通过 latex 运行以生成结果图像并重新包含回原始文档。

答案2

模拟更一般的情况(只是为了好玩)。您可以根据需要进行调整。

\documentclass{article}


\usepackage{filecontents}
\begin{filecontents*}{layout.tex}
\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage[a6paper,margin=1cm,showframe]{geometry}
\usepackage{lipsum}
\begin{document}
\section*{Minipage}
\noindent
\fbox{%
\begin{minipage}{.45\linewidth}
Left Minipage
\end{minipage}}
\hfill
\fbox{
\begin{minipage}{.45\linewidth}
Right Minipage
\end{minipage}}

\section*{Hello World}
{\tiny\lipsum[1]}
\end{document}
\end{filecontents*}


\immediate\write18{pdflatex layout.tex}

\usepackage[a5paper,vmargin=1.5cm,hmargin=1cm,landscape]{geometry}
\usepackage{xcolor,showexpl,lipsum}
\lstset
{   
    language={[LaTeX]TeX},
    basicstyle=\scriptsize\tt,
    backgroundcolor=\color{yellow!50},
    numbers=none,
    frame=single,
    breaklines,
    explpreset={},
    pos=r,
    varwidth,
}

\begin{document}
\section*{How to write a report with \LaTeX}
\LTXinputExample[graphic=layout.pdf,width=.5\textwidth]{layout.tex}
\lipsum[1-2]
\begin{figure}
\centering
\includegraphics[width=.5\linewidth]{layout}
\caption{The layout of our project report.}
\label{fig:layout}
\end{figure}
\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容