0

updated 10/12 Thank you @Rmano, I failed to reply well in the comment section, so I show my problem here:

I tried

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L,C]{}
\fancyhead[R]{test}

it came out fine. The word "test" appears in the header. enter image description here

But when I tried

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L,C]{}
\fancyhead[R]{\includegraphics{example-image}}

It couldn't produce anything. What am I missing here? Where can I study the whole thing through?


Original post:

I'm a total beginner of the LaTeX system. I'm writing lecture handouts for my students, and I'm choosing which software to use. I learned that LaTeX is better at scientific expression, but I have a problem: I want the handouts to be able to use decorative chapter/section titles and page numbers.

I want to know if it's possible, and if so, what should I learn.( I mean like which package can do this)

What I want is something like the following (the real pictures would be more complicated): page number on top leftpage number on top left page number on top rightpage number on top right section titlessection titles

My questions are

  1. How can I set the format of page numbers, and make sure the left hand pages get the left page number image, and the right hand pages get the right page number image?

  2. How can I set the format of section titles ( I mean like creating a code "format1"), so I can type something like "\format1 point A ; alkanes" and "\format1 point B ; alkenes" in TeX, and it creates the corresponding images as section titles?

Wang
  • 103
  • 1
    For an extreme example of decorated section titles see https://tex.stackexchange.com/a/63759/1090 – David Carlisle Oct 11 '21 at 15:57
  • 1
    This: https://tex.stackexchange.com/a/367190/38080 is a bit less fancy than the one pointed to by @DavidCarlisle, but can give another idea... – Rmano Oct 11 '21 at 17:02
  • @DavidCarlisle thank you. I want to export my image to tikz, and I find the svg2tikz (formally known as inkscape2tikz) page : https://github.com/xyz2tex/svg2tikz But I don't know how to use it. I imagine it would have had an exe file and I could open it, put the image in. Could you tell me how this page works? – Wang Oct 12 '21 at 05:29
  • @Rmano thank you. Can I include my own drawing into fancyhdr's header, and let it produce page number automatically? – Wang Oct 12 '21 at 05:36
  • 1
    are you sure you need to convert it to tikz? there isn't a lot of point unless you need to edit the generated tikz, I only used inkscape to tikz once but like many code generators it generates code that is a lot more complicated than is necessary so hard to edit, but I just provided the link to an old answer, it wasn't my answer and I haven't looked in detail about what code it used. – David Carlisle Oct 12 '21 at 06:55
  • my problem is I now know fancyhdr is able to place headers, but I can't find how to put my image as headers. So I think maybe inkscape to tikz may work. Is there a better way for this purpose? – Wang Oct 12 '21 at 07:09
  • 1
    You can include images with \includegraphics directly --- even into a TikZ node text. But you should prepare a small example, complete, showing us where you got stuck so that we can help you... – Rmano Oct 12 '21 at 09:11
  • 1
    @Wang, please edit your question adding the code there --- in the comments it's impossible to see. You can use example-image for the image, it's in all LaTeX distribution – Rmano Oct 12 '21 at 10:15
  • @Rmano Thank you. I edited my question, and I changed the picture to example-image. It still didn't produce anything. What did I do wrong here? – Wang Oct 12 '21 at 10:23

1 Answers1

1

Probably you are missing some package and got errors. Never ignore errors! And, especially when using fancyhdr, look at the warnings too...

This snippet:

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L,C]{}
\fancyhead[R]{\includegraphics[height=2cm]{example-image}}
\addtolength{\headheight}{2.5cm}
\begin{document}
\lipsum
\end{document}

gives:

enter image description here

Now, playing with positioning, image sizes, and other things is not completely easy (normally using pict2e and the put command helps he lot), but I think you got the idea.

You can put whatever you want in the "spots" in header and footer; the only problem in that case is the alignment --- but in case you have that problem, there are plenty of questions here about that. Or you can ask a specific one with a well-designed minimal working example (MWE).

To give you an idea: if you change the \fancyhead[R] line with:

\fancyhead[R]{\Large\textbf{\arabic{page}}\quad
    \includegraphics[height=2cm]{example-image}}

You'll have:

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • Thank you! I think I missed the \graphicx code. I changed the image, and successfully put my image in! Now I face the last part of my problem: How can I add the page number to the code so I can have my image + the page number in the headers? – Wang Oct 12 '21 at 13:05
  • 1
    Like changing the [L,C] line with \fancyhead[C]{}\fancyhead[L]{\arabic{page}}? That will put the page number on the left, in Arabic (normal) numerals. You have a lot of examples in the manual, https://texdoc.org/serve/fancyhdr/0 – Rmano Oct 12 '21 at 13:24
  • Thank you. But can I have the image and the page number both on the right? What I'm aiming is that my image has a decorative line ( like the one in my question) , and the page number sits on the line. Can I have them both on the right, and position them independently? – Wang Oct 12 '21 at 13:31
  • 1
    I added another example --- now, please, experiment a bit after looking at fancyhdr documentation and if you have more questions, please ask another specific question --- this is how this site is supposed to work: one specific question per question (eh!), so that it will be useful to more people than just you! – Rmano Oct 12 '21 at 13:40
  • Thank you! I will add what you provide to the topic, so more people can find them. Sorry I'm totally lost at first, so the questions are so fragmental. – Wang Oct 12 '21 at 13:47