简体   繁体   中英

Multiple commands in an environment in LaTeX

Is it possible to use multiple commands in one environment block in LaTeX? I tried something like this, but it didn't work...

\begin{sffamily,emph}
    I'm sans serif and italic!
\end{sffamily,emph}

No, but there are two ways to get around that:

1) Define your own environment:

\newenvironment{sfemph}{\begin{sffamily}\begin{emph}}{\end{sffamily}\end{emph}}

\begin{sfemph}your text here\end{sfemph}

2) Use the non-environment forms (though this doesn't work for every command):

{\sffamily\emph your text here}

The syntax does not exist (AFAIK) to begin and end two environments in one statement, as it seems you're trying to do by separating your environment names with a comma. I'm not sure why you'd think this would work, possibly just not being familiar with LaTeX syntax and style. As dlamblin said, why not something like this:

\begin{sffamily}
    \begin{emph}
        I'm sans serif and italic!
    \end{emph}
\end{sffamily}

This is the most general solution. However, if you're trying to just emph and sans serif text, there are other ways to de-serif-ify your font. Have you looked at the invaluable Not-so-short Intro to LaTeX ? If not, you should - it gives a really good high-level approach to using and thinking about LaTeX, in addition to plenty of answers to "how-do-I-..." type questions.

The wording on this help site

LaTeX provides a number of different paragraph-making environments. Each environment begins and ends in the same manner.

 \begin{environment-name}
 ....
 ....
 \end{environment-name}

sounds to me like you can use precisely one environment per begin/end statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM