2

I am trying to put multiple hspace into one line of text to get something like this:

Picture

So I want that the "where the customer can..." comes exactly under "In the Date Control". How can I solve this?

My Latex code is this:

\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).\\
  • Why not use a description environment or even a table for this? – leandriis Jun 18 '18 at 22:05
  • @leandriis if I use a table it will be shown in my seminar paper under Content of tables. How can I solve it without tables? Or possible WITH a table that will not shown in the content of table? – Belfort90 Jun 18 '18 at 22:07
  • 1
    Hi, welcome. At the start of a line you need to use \hspace*{4mm}, note the *. That said, a (possibly modified) description environment is likely a better way of doing this, at least if you're doing several of these. Note a table only appears in the list of tables if you add a \caption to it, which of course isn't mandatory. – Torbjørn T. Jun 18 '18 at 22:09
  • @TorbjørnT. thank you very much. I am trying it now with a table but my text is not starting at a new line, its just writing till the end of the paper. How can I avoid this? – Belfort90 Jun 18 '18 at 22:13
  • 1
    I wouldn't use a table for this. Will you have several definitions like that after one another (like a list), or just one at a time? – Torbjørn T. Jun 18 '18 at 22:15
  • I will have several of them. Around 4. But later on in my document I have to define again other 4 and again etc. – Belfort90 Jun 18 '18 at 22:16

3 Answers3

4

If you find yourself manually adding formatting like this, then it might be a good idea to ask if there are better ways of doing the same. What you're making looks a bit like a standard description list, but with the added |.

You can use the package enumitem to define a new type of list (here called mydesc, but you can give it a more sensible name). The code example below has some comments, ask if anything is incomprehensible.

enter image description here

\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}
Torbjørn T.
  • 206,688
1

Two other possibilities, with linegoal and tabularx respectively:

\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} 

enter image description here

Bernard
  • 271,350
  • I chose your options because it was for me the best one. I am also trying to get a hspace for a \begin{lstlisting}. But if I put hspace before it it doesnt appear? How can I solve this? – Belfort90 Jun 19 '18 at 10:27
  • You can load changepage`` and nestlstlisting in, say \begin{adjustwidth}{1cm}{} ... \end{adjustwidth}. The first argument is for the left margin, the second one for the right margin. An empty argument means no modification on that side. – Bernard Jun 19 '18 at 11:11
0

A simple tabular option with no additional packages is

\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}

adjust the 9cm to get what you need for your page width

Esme_
  • 657
  • 7
  • 15