如何调整宏以尊重当前\线宽?

如何调整宏以尊重当前\线宽?

\textwidth我的文字超过了我发布的末尾这个关于为什么要放置文本超出指定线宽度的问题。那里提供的 MWE 产生了与我的情况类似的情况。添加\sloppy修复了该 MWE 中发布的所有问题,但当我在更大的文档中使用它时,它对输出完全没有影响。

进一步缩小我的问题范围,我发现问题源于宏\iteminput,这是提供的解决方案修复了包含小页面的列表中项目编号的对齐问题standalone我一直在使用它来输入我的standlalone文件。

似乎\iteminput忽略了这一事实,\linewidth因为它已经在enumerate列表中,所以我的问题是:如何调整\iteminput宏以尊重当前\linewidth

实现此目的的 MWE 需要两个文件。第一个文件是standalone名为 Item-from-File.tex 的文件:

\documentclass[preview=false]{standalone}
\usepackage{standalone}
\usepackage{paralist}

% geometry settings identical to main file.
\usepackage{geometry}
\geometry{top=0.5in}
\geometry{bottom=0.5in}
\geometry{paperheight=11.0in}
\geometry{paperwidth=8.5in}
\geometry{textwidth=6.0in}
\geometry{left=1.125in}
\geometry{right=1.125in}
\geometry{showframe=true}

\begin{document}
  Here is a line of text, but one that is from a separate standalone file.
  This file typeset by itself is fine. When this is input into an enumerated list 
  via the normal input macro, things are also fine. But the text goes past the end
  of the line if input with modified input macros.
  %
  % Updated to include following:
  \begin{enumerate}[(a)]
     \item First item: If this sentence is long enough things are not so good when 
           this is included in another file. But things are fine in this standalone 
           file.
     \begin{enumerate}[(i)]
       \item First sub-item: If this sentence is long enough things are not so good 
             when this included in another file. But things are fine in this 
             standalone file.
     \end{enumerate}
  \end{enumerate}
\end{document}

第二个是主文件:

\documentclass{article}
\usepackage{standalone} % Needed for the standalone file
\usepackage{paralist}

% geometry settings identical to standalone file.
\usepackage{geometry}
\geometry{top=0.5in}
\geometry{bottom=0.5in}
\geometry{paperheight=11.0in}
\geometry{paperwidth=8.5in}
\geometry{textwidth=6.0in}
\geometry{left=1.125in}
\geometry{right=1.125in}
\geometry{showframe=true}

\newcommand{\iteminput}[2][\topskip-1bp]{%
  \leavevmode\vtop{\hrule height 0pt\kern-\dimexpr#1\relax
    \input{#2}}}


\begin{document}
Text in this file, things work great:
\begin{enumerate}
  \item When this text appears in the same file things are ok.
        The line goes to the end of the correct spot on the page and wraps around.
  \item \input{Item-from-File.tex}% This is ok
  \item \iteminput[2.5ex]{Item-from-File.tex}% This is a problem
\end{enumerate}
\end{document}

答案1

只需将所需的线宽度传递到宏即可。

\newcommand{\iteminput}[2][\topskip-1bp]{%
  \leavevmode\vtop{
    \hsize=\linewidth\hrule height 0pt\kern-\dimexpr#1\relax
    \input{#2}}}

正如弗兰克·米特尔巴赫在另一个答案,添加\@totalleftmargin=0pt对于避免不良凹痕是必要的(外部的凹痕都保留在内部):

\makeatletter
\newcommand{\iteminput}[2][\topskip-1bp]{%
  \leavevmode\vtop{
    \hsize=\linewidth\hrule height 0pt\kern-\dimexpr#1\relax
    \@totalleftmargin=\z@
    \input{#2}}}
\makeatother

相关内容