Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use classsicthesis style for my PhD. Since this style is somehow geared towards using the outside margin for additional notes and stuff, I thought I could also place the legends of my plots there. I use pgfplots to create them. I styled my plots so that the legend is placed outside the plot. The problem I don't know how to solve (and I really wonder if it can be done) is:

How can it be automatically determined if the plot is on the even or odd page so that the legend always appears on the outside margin?

At the moment I can only do this manually by placing the following two lines in the code of each plot:

 legend style={at={(-0.1,1)}, anchor=north east}, %for even pages
%legend style={at={( 1.1,1)}, anchor=north west}, %for odd pages

and (un)commenting the appropriate line - which, of course, is not practical at all. An automated solution would be great - otherwise it's just not worth it for a lengthy document with lots of plots.

P.S.: I am using TexLive 2011 on Ubuntu 11.10

EDIT: I thought of the question as kind of a general problem, but I was probably wrong, so I created the following MWE to illustrate it a help with the alternative answers:

% legend style={at={(-0.1,1)}, anchor=north east}, %for even pages
legend style={at={( 1.1,1)}, anchor=north west}, %for odd pages
\addplot coordinates { (0,0) (1,1) };
\addlegendentry{Legend entry}
share|improve this question
Code snippets are useful to explaining things, but it is always best to compose a MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it, and so they can easily test the solution as well. –  Peter Grill Nov 5 '11 at 17:39
This question is now answered, but as Peter says it would be good to include a minimal working example. That way alternative answers can be tested easily. –  qubyte Nov 6 '11 at 0:18

1 Answer 1

up vote 4 down vote accepted

Assuming that odd pages are always on one side and even on the other, you can add the package ifthen


and then use the page number to determine the side

\ifthenelse{\isodd{\value{page}}}{\def\eastwest{north east}}{\def\eastwest{north west}}

i.e. use that line just inside your figure environment if you're wrapping a plot in one. Now replace the line you have with

legend style={at={(-0.1,1)}, anchor=\eastwest},

I'm not sure how this will interact with floats, but I imagine it'll work.

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.