GeneralFigure number in head of page-of-floats with fancyhdr

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Figure number in head of page-of-floats with fancyhdr

Post by Bozack »

I am making my thesis, and am playing around with all kinds of little optimizations for the look of the document. There is one thing I haven't been able to figure out though, and I hope that someone here might be able to point me in the right direction.

I want the header of my page-of-float's to contain the figure number (maybe figure numbers somehow automatically if there are more than one figure on the page). Right now, my header is configured with fancyhdr as in the following MWE:

Code: Select all

\documentclass{book}
\usepackage{fancyhdr}
  \fancyfoot{}
  \fancyhead[LO]{\iffloatpage{}{\nouppercase{\leftmark}}}
  \fancyhead[RE]{\iffloatpage{}{\nouppercase{\rightmark}}}
  \fancyhead[RO]{\thepage}
  \fancyhead[LE]{\thepage}
  \pagestyle{fancy}
\usepackage{lipsum}
\begin{document}

  \chapter{Chapter one}
  \lipsum[1]
  \section{Section one}
  \lipsum[2-3]

  \begin{figure}[p]
    \centering
    \rule{100mm}{150mm}
    \caption{figure one}
  \end{figure}

  \section{Section two}
  \lipsum[4-9]

  \begin{figure}[p]
    \centering
    \rule{100mm}{40mm}
    \caption{figure two}
  \end{figure}

  \begin{figure}[p]
    \centering
    \rule{100mm}{100mm}
    \caption{figure three}
  \end{figure}

  \section{Section three}
  \lipsum[7-8]

\end{document}
This gives the following pages, where I've marked in red what I want to happen where.
overview2.png
overview2.png (132.61 KiB) Viewed 6590 times
Any suggestions?
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Figure number in head of page-of-floats with fancyhdr

Post by Johannes_B »

I wouldn't do that if i were you, seriously. This is inconsistent and bad.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Figure number in head of page-of-floats with fancyhdr

Post by Bozack »

Johannes_B wrote:This is inconsistent and bad.
Just out of curiosity, why would it be inconsistent? I know I'm nitpicking here.

Right now I simply have the headers on page-of-floats be empty apart from the page number (just like in the MWE). Do you have any suggestions to alternatives, or do you think this is for the best?

I am very much against having the \rightmark on a page-of-floats, since I sometimes have very small sections, and a page-of-float then might show a section name that the figure doesn't belong to. On the other hand, \leftmark (chapter) isn't as big a deal, since all figures belonging to a chapter should be set before the next chapter starts anyway.
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Figure number in head of page-of-floats with fancyhdr

Post by Johannes_B »

I would indeed leave the standard (leftmark, rightmark) on the pages. Since floats don't get out of order, they will stay in the document logic, maybe at a later place.
A picture has a caption, that describes what the picture is, what is seen on the picture.
In some books, all pictures are deferred to the appendix.


If you really want to do this, you would need to set the header by hand. If just one picture is on the page, ok. If two are present, you would need an and construct, this would again change when three pictures are present. Getting the numbers of the pictures would be hell as well and an insane amount of coding.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Figure number in head of page-of-floats with fancyhdr

Post by Bozack »

Johannes_B wrote:Since floats don't get out of order, they will stay in the document logic, maybe at a later place. [...] A picture has a caption, that describes what the picture is, what is seen on the picture.
I still feel like it is wrong seeing the section header of a later section, when a figure belonging to an earlier section is finally shown - descriptive captions or not. Maybe I simply have to \clearpage my way out of this and force the few problematic figures to be typeset earlier (I'm not a big fan of forcing layout like that though). Or I will simply keep the page-number-only-for-float-pages as I have now.
Johannes_B wrote:If you really want to do this, you would need to set the header by hand. If just one picture is on the page, ok. If two are present, you would need an and construct, this would again change when three pictures are present. Getting the numbers of the pictures would be hell as well and an insane amount of coding.
I guess this was what I expected to be told to begin with, but hoped that I wouldn't. You've convinced me to stop pursuing this, thank you :D

I'll mark the topic as solved and let it stay for future reference.
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Figure number in head of page-of-floats with fancyhdr

Post by Johannes_B »

Package placeins knows a command \FloatBarrier which might be handy for you. It is in fact not much more than a simple \clearpage
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Figure number in head of page-of-floats with fancyhdr

Post by Stefan Kottwitz »

Johannes_B wrote:It is in fact not much more than a simple \clearpage
To add a bit to be more specific: in contrast to \clearpage, \FloatBarrier doesn't break the page if no float is waiting.

Stefan
LaTeX.org admin
User avatar
Bozack
Posts: 117
Joined: Wed Feb 06, 2008 4:21 pm

Figure number in head of page-of-floats with fancyhdr

Post by Bozack »

Stefan_K wrote:\FloatBarrier doesn't break the page if no float is waiting.
Pretty important difference. Thanks for clarifying! :)
OS, LaTeX-system, editor: Arch Linux 64bit, TeXlive, Kile | Windows 10 Professional 64bit, MikTeX 4.9, TeXnicCenter 2.02 64bit
Post Reply