2

I was using the fancyhdr package to edit headers in my article, and the headers seem to work for every page except for the last.
My code looks like this:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amsthm,amssymb,scrextend}
\usepackage{fancyhdr}
\usepackage{CJKutf8}
\usepackage{setspace}
\usepackage[a4paper, top=1.5in, bottom=1.5in]{geometry}

\onehalfspacing
\begin{document}
\pagestyle{fancy}
\fancyhf{}
\begin{CJK*}{UTF8}{bsmi}
\fancyhead[L]{[left header]}
\fancyhead[C]{[center header]}
\fancyhead[R]{[right header]}

[some content]

\newpage
[some content]

\end{CJK*}
\end{document}

What is the problem here? Whenever I add a new page, the headers for the original last page automatically show up, and the new last page still does not have any headers, although it does have the line that spans across the top of the page.
Much appreciated.

2
  • you are setting the heading inside a group which ends at the end of the evironment, before the last page is shipped out Sep 17, 2022 at 16:09
  • 1
    Put a \newpage (or \clearpage/\cleardoublepage, whatever is appropriate) before \end{CJK*} Sep 17, 2022 at 19:23

1 Answer 1

2

As David mentions in the comments, you are defining the headers and footers for fancy style only inside the CJK* environment, which ends right before the end of the document.

Outside of that environment you get the default fancy style, which you haven't redefined.

I think it's best to put all the header and footer settings in the preamble.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath, amsthm,amssymb,scrextend}
\usepackage{fancyhdr}
\usepackage{CJKutf8}
\usepackage{setspace}
\usepackage[a4paper, top=1.5in, bottom=1.5in]{geometry}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[L]{[left header]}
\fancyhead[C]{[center header]}
\fancyhead[R]{[right header]}

\onehalfspacing
\begin{document}

\begin{CJK*}{UTF8}{bsmi}

[some content]

\newpage
[some content]

\end{CJK*}
\end{document}

If you want different headers and footers in portions using different languages, I would use different styles, rather than redefining fancy, but reserve the default style (set by the \pagestyle command in the preamble) for whatever you do want on the last page. (I'm happy to provide further help with that if you give more details about what you want.)

3
  • I want to use some Chinese characters I. The headers, which is why I included the /fancyhead lines inside the CJK environment. Is there any way to do this? I want the headers to be the same throughout the entire document. Thank you.
    – WinnieXi
    Sep 17, 2022 at 17:13
  • I would think you could put CJK* environments in the headers themselves, e.g., \fancyhead[L]{\begin{CJK*}{UTF8}{bsmi}...header contents ...\end{CJK*}}, but if that doesn't work for you, could you edit your question to include the actual Chinese characters needed (the site supports UTF8) so we can test ourselves?
    – frabjous
    Sep 17, 2022 at 17:35
  • That worked! Thank you so much.
    – WinnieXi
    Sep 18, 2022 at 4:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .