TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have this short code that uses the \aftergroup command to inject a \centering before inserting a figure and then tries and restore the paragraph settings after the image is typeset.

enter image description here

I am trying to modify the code so that it can detect the environment that was in before the macro was expanded, i.e if the previous settings were justified then after the image is typeset the environment is restored. How do I do this?

Minimal shown below:


\def\agraphic{{\begin{minipage}{3cm}\par \includegraphics[width=\textwidth]{./graphics/amato}\end{minipage}\par}}
\def\testafter{{ \gdef\aword{\centering}\aftergroup\aword\aftergroup \agraphic\aftergroup\flushleft }}
share|improve this question
What about @currenvir? – mbork Nov 14 '11 at 23:22
Also, you might want to test the values of \leftskip and \rightskip. – mbork Nov 14 '11 at 23:23
Isn't it sufficient to say \par{\centering\includegraphics[...]{...}\par}? – egreg Nov 14 '11 at 23:24
You right I am not sure if @currenvir would do, values could be set from the class definitions or from inline code. – Yiannis Lazarides Nov 14 '11 at 23:26
@egreg This is an extract from some long code, I need to escape outside the enclosing groups. – Yiannis Lazarides Nov 14 '11 at 23:27
up vote 6 down vote accepted

It's possible to avoid cumbersome code by simply saying


that will restore the previous settings, but center the picture.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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