如何在一行中插入多个 hspace?

如何在一行中插入多个 hspace?

我试图将多个 hspace 放入一行文本中以获得如下效果:

图片

所以我希望“客户可以在哪里...”正好位于“日期控制”下。我该如何解决这个问题?

我的 Latex 代码是这样的:

\hspace{4mm}\textbf{Date Control}  \hspace{4mm}| \hspace{4mm}In the Date Control box the \textit{dateRangeInput()} function has been inserted, where the customer can select by clicking on the left and right date between a date period (from - to).\\

答案1

另外两种可能性,分别为linegoaltabularx

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum} %
\usepackage{linegoal}
\usepackage{tabularx}

\begin{document}

\lipsum[1] %
\noindent\hspace{4mm}\textbf{Date Control} \hspace{4mm}| \hspace{4mm}\parbox[t]{\linegoal}{In the Date Control box the \textit{dateRangeInput()} function has been inserted, where the customer can select by clicking on the left and right date between a date period (from - to).\\}
\lipsum[2]

\noindent\begin{tabularx}{\linewidth}{@{\hspace{4mm}}>{\bfseries}l@{\hspace{4mm}|\hspace{4mm}}X@{}}
Date Control & In the Date Control box the \textit{dateRangeInput()} function has been inserted, where the customer can select by clicking on the left and right date between a date period (from - to).\\
\end{tabularx}

\end{document} 

在此处输入图片描述

答案2

如果您发现自己手动添加了这样的格式,那么最好问问是否有更好的方法来实现相同的效果。您制作的内容看起来有点像标准description列表,但添加了|

您可以使用包enumitem来定义一种新类型的列表(这里称为mydesc,但您可以给它一个更合理的名称)。下面的代码示例有一些注释,如果有任何难以理解的地方,请询问。

在此处输入图片描述

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lipsum} % for making dummy text. only for example

\usepackage{enumitem} % for customizing lists
\SetLabelAlign{leftwithbar}{#1\quad|\quad} % (ab)use this to add the vertical bar. A \quad is horizontal space, same as \hspace{1em}
\newlist{mydesc}{description}{1} % create a new list called mydesc, of type "description"
\setlist[mydesc]{
  align=leftwithbar, % use the align-format defined above
  leftmargin=0pt, % indentation for all the lines
  labelindent=1em, % horizontal space before label
  labelsep=0pt % horizontal space after label -- set to zero because we add space via "leftwithbar"
} 
\begin{document}
\lipsum[1] % dummy text
\begin{mydesc}
  \item[Date Control] In the Date Control box the \textit{dateRangeInput()} function has been inserted, where the customer can select by clicking on the left and right date between a date period (from -- to).
  \item[Something else] Lorem ipsum \dots
\end{mydesc}
Then later in your document, when you need another one like this, just make a new list:
\begin{mydesc}
  \item[Foo] Bar
  \item[Baz] Etc.
\end{mydesc}
\lipsum[2] % more dummy text

\end{document}

答案3

无需额外软件包的简单表格选项

\begin{tabular}{p{4mm} l p{4mm} | p{9cm}}
& \textbf{Date Control} & & In the Date Control box the \textit{dateRangeInput()} function has been inserted, where the customer can select by clicking on the left and right date between a date period (from - to).
\end{tabular}

调整 9cm 以获得所需的页面宽度

相关内容