一行兩端都有文字的下劃線

一行兩端都有文字的下劃線

我想在一行兩端的文字之間留出空白。例如,一行兩端的文字之間有一個空格

\begin{enumerate}
\item There \hrulefill\ in the room.
\end{enumerate}

但是,上面的內容僅出現在學生版本中,我想製作一個教師版本,其中答案也印在空白處。我不知道但是

\begin{enumerate}
\item There \underline{\makebox[100pt][l]{is a chair}} in the room.
\end{enumerate}

此方法並不令人滿意,因為毛坯的長度事先是未知的。

我的問題:

  1. 如何在 上放置文字\hrulefill

  2. \hrulefill(獎勵問題)我發現和產生的水平線的垂直位置\underline是不同的。如何控制這些水平線的垂直位置?

答案1

雖然 cslstr 的方法更加穩健,但實現此目的的一種方法是將 替換\hrulefill為使用下劃線的方法\xleaders

\documentclass[letter,10pt]{article}
\newcommand{\ulfrule}{\xleaders\hbox{\underline{ }}\hfill\kern0pt}
\begin{document}
\begin{enumerate}
\item There \hrulefill{} in the room.
\item There \ulfrule{} in the room.
\item There \ulfrule{}\underline{is a chair}\ulfrule{} in the room.
\end{enumerate}
\end{document}

其產生: 範例輸出

如果您希望答案保持對齊,您可以刪除\ulfrule{}答案之前的開頭:

\documentclass[letter,10pt]{article}
\newcommand{\ulfrule}{\xleaders\hbox{\underline{ }}\hfill\kern0pt}
\begin{document}
\begin{enumerate}
\item There \hrulefill{} in the room.
\item There \ulfrule{} in the room.
\item There \underline{is a chair}\ulfrule{} in the room.
\end{enumerate}
\end{document}

更多關於什麼\xleaders的內容可以找到在這個答案中

答案2

這是一個簡單的實作:

\documentclass{article}

\newif\ifteacher % starts out false

\newcommand{\fillanswer}[2][\fill]{%
  \unskip\ \lhrulefill{#1}%
  \ifteacher\makebox[0pt]{#2}\fi
  \lhrulefill{#1}\ \ignorespaces}
\newcommand{\lhrulefill}[1]{%
  \leavevmode
  \leaders\hrule height -.3ex depth \dimexpr .3ex+.4pt\relax % define the leader
  \hskip\glueexpr#1/2\relax\relax % how much it should extend
  \kern0pt
}


\begin{document}

\begin{enumerate}
\item There \fillanswer{is a chair} in the room.

\item There \fillanswer[5cm]{is a chair} in the room.

\teachertrue
\item There \fillanswer{is a chair} in the room.

\item There \fillanswer[5cm]{is a chair} in the room.
\end{enumerate}

\end{document}

在此輸入影像描述

可選參數的預設值為\fill,這意味著本質上\hrulefill已執行(但規則降低)。實際上我們設定\ifteacher當設定為 true時,規則和它們之間的零寬度框。

答案3

此方法使用\uline巨集的一些重新定義ulem僅列印某些文字的下劃線(文字本身不可見)。 (看這個答案以獲得類似的解決方案。

我在文字的每一側都添加了一些空間,因此空白比所需的要大一些(以允許手寫)。如圖所示,這也將優雅地處理很長的“空白”,這些“空白”最終會延伸到多行。

學生版是透過保留第一個\let\filltheblanks...指令並註釋第二個指令來製作的。教師版本註解第一個指令並保留第二個指令。

\documentclass[]{report}

\usepackage{enumerate}
\usepackage[normalem]{ulem}

\begin{document}
\LARGE % Size seemed appropriate for this type of assignment

% Fill-in-the-blank command
\newcommand{\fillintheblank}[1]{\uline{\qquad#1\qquad}}

% For Student Version
\let\filltheblanks\phantom

% For Teacher Version
\let\filltheblanks\null

% Redefined \uline
\makeatletter
\def\UL@putbox{\ifx\UL@start\@empty \else % not inner
  \vrule\@width\z@ \LA@penalty\@M
  {\UL@skip\wd\UL@box \UL@leaders \kern-\UL@skip}%
    \filltheblanks{\box\UL@box}%
  \fi}
\makeatother
%%%%%%%%%%%%%%%%


\begin{enumerate}[1.]

\item There \fillintheblank{was a dog} in the room.

\item There \fillintheblank{was a very, large, wet and disgusting looking dog} outside my door.

\end{enumerate}

\end{document}

學生版:

學生版

教師版:

教師版

答案4

答案的變體建立文件的填空版本,能夠開啟和關閉空白

它提供\answer連續底線(帶換行符)和\answerwords逐字底線。取消\TeacherCopy序言中的註釋,並取得教師版本。

編輯,根據曼努埃爾的要求,我為學生的答案留出額外的空間,這是通過\Huge在開始下劃線遮光之前將字體大小設置為,然後在之後重置它來完成的(請注意,這不會影響分配給答案的垂直高度,因為巨大的文字被轉換為相同寬度的垂直挑戰規則)。

重新編輯,以便教師版本提供與學生版本相同的字間距。

可以更改和\censorruleheight\censorruledepth分別更改標高、標尺厚度和位置。

\documentclass{article}
\usepackage{censor}
\usepackage{xcolor}
\usepackage{readarray}
\usepackage{ifthen}
\censorruledepth=-.2ex
\censorruleheight=.1ex
\newcounter{index}
\def\mysize{\Huge}
\def\answer#1{\mysize\xblackout{#1}\normalsize}
\def\answerwords#1{\mysize\blackout{#1}\normalsize}
\def\TeacherCopy{%
  \def\answer##1{%
    \color{red}%
    \getargsC{##1}%
    \setcounter{index}{0}%
    \whiledo{\theindex<\narg}{%
      \stepcounter{index}%
      \setbox0=\hbox{\mysize\csname arg\romannumeral\theindex\endcsname}%
      \underline{$\vphantom{g}$%
                 \makebox[\wd0]{\csname arg\romannumeral\theindex\endcsname}}%
      \mysize\ \normalsize%
    }%
    \unskip%
    \color{black}%
  }%
  \let\answerwords\answer%
}
%\TeacherCopy
\parindent0pt
\begin{document}
\begin{enumerate}
\item And the answer to life, the universe, and everything, is \answer{forty two}.

\item The beginning six words of the Gettysburg Address are 
\answerwords{Four score and seven years ago}.

\end{enumerate}
\end{document}

學生副本:

在此輸入影像描述

老師抄:

在此輸入影像描述

相關內容