2

I'm trying to add margin to text but I have a little problem. I want to get rid of newline after first text. My code is

\documentclass{article}

\usepackage{lipsum}
\usepackage{scrextend}

\begin{document}
    \noindent Text
    \begin{addmargin}[40pt]{0pt}
        \lipsum[11]
    \end{addmargin}
\end{document}

The output is

compiled code

What I am expecting

expected output

How can I do it? Thanks.

2
  • 1
    When i see that, i am thinking of a description (or labeling) list. Or of marginal notes. Can you explain in more detail, what you are trying to achieve instead of saying how you can improve what you currently have?
    – Johannes_B
    Dec 12 '15 at 20:11
  • 1
    \begin{description}\item[Text} Sed ...... ? Dec 12 '15 at 20:21
2

Here are three ways to do it:

\documentclass{article}
\usepackage{lipsum}
\usepackage{scrextend}
\usepackage{enumitem}

\begin{document}

\noindent Text\vspace*{-\baselineskip}
\begin{addmargin}[40pt]{0pt}
  \lipsum[11]
\end{addmargin}

\vskip1cm

\leftskip=40pt\noindent
\llap{\makebox[40pt][l]{Text}}\lipsum[11]

\vskip1cm

\begin{description}[font=\normalfont, leftmargin=40pt, labelwidth =\dimexpr40pt-\labelsep\relax]
  \item[Text] \lipsum[11]
\end{description}

\end{document} 

enter image description here

3

enter image description here

\documentclass{article}

\usepackage{lipsum}
\usepackage{scrextend}

\begin{document}

\begin{description}
\item[Text]
        \lipsum[11]
\end{description}

\end{document}

the exact indentation and fonts used can be customised by setting the list parameters either directly or more easily using the enumitem package, but this shows the basic markup.

1

Here is an addmargin implementation that you can nest and adjust margins with, and also add "titles" with:

enter image description here

\documentclass{article}

\usepackage[margin=1in,showframe]{geometry}% Just for this example

\usepackage{lipsum}
\usepackage{xgalley}

\ExplSyntaxOn
% http://river-valley.zeeba.tv/media/conferences/tug-2015/0302-Joseph-Wright/
\cs_new_eq:NN \SetAbsMargins \galley_margins_set_absolute:nn % {<left margin>}{<right margin>}
\cs_new_eq:NN \SetRelMargins \galley_margins_set_relative:nn % {<left margin>}{<right margin>}
\ExplSyntaxOff

\newcommand{\inserttitle}{}
\newenvironment{addmargin}[2][40pt]
  {%
    \renewcommand{\inserttitle}[1]{%
      \noindent\makebox[0pt][r]{\makebox[#1][l]{\bfseries ##1}}%
      \ignorespaces}%
  \SetRelMargins{#1}{#2}\ignorespaces}
  {\par}

\begin{document}

\sloppy% Just for this example

\begin{addmargin}{0pt}
  \inserttitle{Text}
  \lipsum[11]

  \lipsum[12]

  \begin{addmargin}[75pt]{20pt}
    \inserttitle{More text}
    \lipsum[11]
  \end{addmargin}

  \inserttitle{Text\ldots}
  \lipsum[13]
\end{addmargin}

\end{document}

The default left-margin width is 40pt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.