How to correctly use \newenvironment

I would like to use a \newenvironment in my .tex file. It should use a serif font and should be left aligned.

Can someone show me the correct syntax?

• is the enviornment that you want to define the same as \begin{flushleft}...\end{flushleft} ? – David Carlisle Feb 28 '18 at 10:11
• Which serif font? \newenvironment{foo}{\rmfamily}{} should be enough – user31729 Feb 28 '18 at 10:11
• \newenvironment{<environment-name>}{<code-at-begin>}{<code-at-end>}. If you want to have arguments, you can use \newenvironment{<name>}[<arg-count>] and then the rest (similar to \newcommand). The arguments are only available in the begin-part. – Skillmon Feb 28 '18 at 10:11
• could it be a right exmple? \newenvironment{nico}{\begin{FlushLeft}{\end{FlushLeft} \begin{nico} bla bla bla \end{nico} \end{document – RenatoP Feb 28 '18 at 10:41

Here are three ways of defining environments that use serif fonts (\rmfamily here in short) and aligning them to the left. The 3rd way with \NewEnviron uses \sffamily and alignment to the right in order to show the differences.

The \vskip\baselineskip is not necessary, just for visually separating them.

The regular way is \newenvironment, having

\newenvironment{environmentname}[number of args][value of optional argument]{begin code}{end code} -- the example here does not have arguments, so [] can be omitted there. Please note, that the arguments can not be accessed in the {end code} section.

With \NewDocumentEnvironment the syntax is 'similar':

\NewDocumentEnvironment{environmentname}{argument specifications}{begin code}{end code} -- here, the arguments can be used in the end code section.

\NewEnviron from environ package is different in some aspects:

\NewEnviron{environment name}[number of arguments][opt argument value]{environment start code\BODY}[environment end code}.

You need the \BODY macro in order to display the environment content -- this is collected first in \BODY. The end code is optional here.

\documentclass{article}

\usepackage{blindtext}
\usepackage{environ}
\usepackage{xparse}

\newenvironment{foo}{\rmfamily\flushleft}{\endflushleft}

\NewDocumentEnvironment{foobar}{}{\vskip\baselineskip\rmfamily\flushleft}{\endflushleft}

\NewEnviron{foobarbar}{\vskip\baselineskip\sffamily\flushright\BODY}[\endflushright]

\begin{document}
\begin{foo}
\blindtext
\end{foo}

\begin{foobar}
\blindtext
\end{foobar}

\begin{foobarbar}
\blindtext
\end{foobarbar}

\end{document}


Just for example, I am using the bookman package for the Bookman font, which is a roman (serif) font by default -- there is no need to change \rmfamily then:

\documentclass{article}

\usepackage{blindtext}
\usepackage{environ}
\usepackage{xparse}

\usepackage{bookman}

\newenvironment{foo}{\rmfamily\flushleft}{\endflushleft}

\NewDocumentEnvironment{foobar}{}{\vskip\baselineskip\rmfamily\flushleft}{\endflushleft}

\NewEnviron{foobarbar}{\vskip\baselineskip\sffamily\flushright\BODY}[\endflushright]

\begin{document}
\begin{foo}
\blindtext
\end{foo}

\begin{foobar}
\blindtext
\end{foobar}

\begin{foobarbar}
\blindtext
\end{foobarbar}

\end{document}


• wonderful! it works! I would use another font family, because the one that I've declared (cinzel) do not write lowercase. Is it possible? – RenatoP Feb 28 '18 at 11:09
• @RenatoP: You should be able to use any font inside the environments. – user31729 Feb 28 '18 at 11:20
• how can I do that? – RenatoP Feb 28 '18 at 11:52
• @RenatoP: In most cases, it is sufficient to load the font package, assuming that it defines \rmfamily accordingly – user31729 Feb 28 '18 at 14:15