0

I have a command that is defined like this :

\newcommand{\lol}[1]{\vspace{4pt}\color{subheadings}\raggedright\scshape\fontspec[Path = fonts/lato/]{Lato-Reg}\fontsize{9pt}{11pt}\selectfont {#1 \\} \normalfont }

I want to add a margin to this command, but can't find a way to do so properly.

For the moment I am using the scrextend package like this :

\begin{addmargin}[2em]{0em}
\lol{MY TEXT HERE}
\end{addmargin}

But it is cumbersome to add the environment each time I use my lol command.

Is there a way to add the addmargin environment inside the newcommand definition ?

Thanks

0

It would be something like

\setlength{\leftskip}{2em}

or maybe

\addtolength{\leftskip}{2em}

if you want extra indentation in an already indented environment. But manipulating the internal variable \leftskip may be tricky because there can be unwanted interactions with LaTeX's environments.

The problem is, when do you reset the margin? The advantage of an environment is that it is clear when it ends, and moreover, the kind of definitions like the above automatically are undone at the end of the environment. Your command doesn't do that. So you would need another command to reset the margin.

Also another problem is that if you do this in the middle of a paragraph it will apply to the whole paragraph.

0

If you want to get the effect of

\begin{addmargin}[2em]{0em}
\lol{MY TEXT HERE}
\end{addmargin}

the simplest way to do this is to modify your existing definition of \lol to include the \begin\end of the enclosing environment. So you would rewrite your definition¹ as:

\NewDocumentCommand{\lol}{m}{
  \begin{addmargin}[2em]{0em}
    \vspace{4pt}\color{subheadings}\raggedright\scshape\fontspec[Path = fonts/lato/]{Lato-Reg}\fontsize{9pt}{11pt}\selectfont {#1 \\} \normalfont 
  \end{addmargin}
}

  1. Let's all get in the habit of using \NewDocumentCommand in place of \newcommand, OK?

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.