如何从胶水中获取长度

如何从胶水中获取长度

以下代码的目的是用 占据一行的剩余部分parbox。我知道这是错误的方法。那么,如何从胶水中获取长度?

\documentclass{article}
\usepackage{geometry}
\geometry{left=1cm,right=1cm,top=1cm,bottom=1cm}
\geometry{showframe}
\begin{document}
A B C D\parbox{\hfill}{Fill the rest length of this line with a parbox}
\end{document}

答案1

您可以使用记录位置\pdfsavepos并在以后的运行中使用它:

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\geometry{left=1cm,right=1cm,top=1cm,bottom=1cm}
\geometry{showframe}
\def\tx{Fill the rest length of this line with a parbox Fill the rest length of this line with a parbox
Fill the rest length of this line with a parbox Fill the rest length of this line with a parbox
Fill the rest length of this line with a parbox}
\makeatletter
\newcommand\currentpos[1]{%
  \ifcsname length#1\endcsname\else
  \expandafter\gdef\csname length#1\endcsname{0sp}%
  \fi
\pdfsavepos
\write\@auxout{%
  \gdef\expandafter\string\csname length#1\endcsname{\the\pdflastxpos sp}}%
  }
\makeatother
\begin{document}

\noindent X\dotfill X

A B C D \currentpos{a}\parbox[t]{\dimexpr\textwidth-\lengtha+1cm}{\tx}

A B C D E F \currentpos{b}\parbox[t]{\dimexpr\textwidth-\lengthb+1cm}{\tx}


A B C D E F G H \currentpos{c}\parbox[t]{\dimexpr\textwidth-\lengthc+1cm}{\tx}
\end{document}

答案2

只要只需要知道页面上的水平位置,该tabto包就足够了。

\documentclass{article}
\usepackage{geometry,tabto}
\geometry{left=1cm,right=1cm,top=1cm,bottom=1cm}
\geometry{showframe}
\newlength\tolinened
\begin{document}
A B C D%
\tabto{\linewidth}%
\setlength\tolinened{\dimexpr\linewidth-\TabPrevPos}%
\tabto*{\TabPrevPos}%
\parbox[t]{\tolinened}{Fill the rest length of this line with a parbox
  Fill the rest length of this line with a parbox
  Fill the rest length of this line with a parbox
  Fill the rest length of this line with a parbox
  Fill the rest length of this line with a parbox
  Fill the rest length of this line with a parbox
}
\end{document}

在此处输入图片描述

相关内容