I am struggling with fancyhdr package. Specifically, with the following:
\fancypagestyle{mystyle}{
\fancyhead{}
\fancyfoot[C]{\thepage}
\setlength{\headheight}{180pt}
\chead{\includegraphics[width=8cm]{x.png}}
}
The header shows up correctly, but the page number is not shown at all, when using \thispagestyle{mystyle}. Could someone please help me?
In none of the standard latex classes is enough room to accommodate an header of 180pt height without pushing the footer off the page. You can see that the page number is actually printed if you reduce the height of the text area:
\documentclass{article}
\usepackage{graphicx}
\usepackage{fancyhdr}
\fancypagestyle{mystyle}{
\fancyhead{}
\fancyfoot[C]{\thepage}
\setlength{\headheight}{180pt}
\chead{\includegraphics[width=8cm]{example-image-duck}}
}
\usepackage[includeheadfoot,height=15cm]{geometry}
\begin{document}
\thispagestyle{mystyle}
test
\end{document}
Related
\documentclass{article}
\usepackage{geometry}
\usepackage{amsthm, amsmath, amssymb}
\usepackage{anyfontsize}
\newgeometry{vmargin={15mm}, hmargin={12mm}}
\makeatletter
\newcommand{\mathleft}{\#fleqntrue\#mathmargin0pt}
\newcommand{\mathcenter}{\#fleqnfalse}
\makeatother
\begin{document}
\fontsize{18}{21.6}
\mathleft
\begin{gather*}
8x^2+10x-3=0\\\\
8x^2-2x+12x-3=0\\\\
2x(4x-1)+3(4x-1)=0\\\\
(2x+3)(4x-1)=0\\\\
x=-\frac{3}{2}\;or\;\frac{1}{4}\\\\\\\\\\\\
-7x^2-4x+3=0\\\\
-7x^2-7x+3x+3=0\\\\
-7x(x+1)+3(x+1)=0\\\\
(3-7x)(x+1)=0\\\\
x=\frac{3}{7}\;or\;-1\\\\\\\\\\\\
x^2+4=8x-8\\\\
x^2-8x+12=0\\\\
x^2-2x-6x+12=0\\\\
x(x-2)+-6(x-2)=0\\\\
(x-6)(x-2)=0\\\\
x=2\;or\;6
\end{gather*}
\end{document}
When I run this code I get a pdf with the first page blank and some of the actual text outside the page. How can I fix it so that it does not leave a blank page and the text stays in the page so that if it can't fit it creates a new page and puts the text there. Both of these issues disappear if the text between begin gather and end gather is small, but how do I make it work regardless of the amount of text or size of the font? The question is similar to this but I am not using the xcolor package or counters. To get the pdf I am using the TexShop application installed from mactex.
The proof copies of a book laid out with KOMA scrbook show that the inner margins are too narrow. I had BCOR set to 10mm and want to increase them, but my experiments with BCOR set to 20mm show that the layout is the same independent what BCOR value I set. Here my MWE:
\documentclass{scrbook}
\KOMAoptions{paper=
128.5mm:198.4mm, %(5,06" x 7,91") %ziel
BCOR=20mm,
twoside,
headinclude=false, footinclude=false,
headings=normal,
titlepage=true,
% draft=true,
DIV=9, %ziel kleines buch
fontsize=12pt,
}
\usepackage[german]{babel}
\usepackage{lipsum}
\usepackage{geometry}
\usepackage[a4,axes,cross,pdftex,center]{crop}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{ Philosophie}
some text
\lipsum
\lipsum
\end{document}
What is wrong?
My real question is: how can I just move the text area on both pages to the outside (i.e. making the gutter wider) without changing the text area size (and thus preserve line breaks)?
I found a hint in some other questions answered before and the problem was caused by the interaction between the KOMA script and the geometry package. Using the geometry package recalculates the page layout and overwrites the one calculated by scrbook including the BCOR value. This can be avoided when adding the option pass to geometry as in
`\usepackage[pass]{geometry}`.
In general the interaction between the layout calculated by KOMAscript and other package can lead to surprises. The discussion in https://tex.stackexchange.com/questions/182821/div-and-bcor-setting-in-koma-best-practices/183839 is very useful.
I have a footer and header set by using the fancyhdr package in a R-Markdown generated PDF. However, at some point I notcied my footer disappears after the first page, while my header appears in each page as intended. I have no idea why can it be, I tried lots of stuff but nothing seemed to work so far.
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot{}
- \fancyhead{}
- \renewcommand{\headrulewidth}{0pt}
... (some chunks of code go here)
\fancyhead[L]{\includegraphics[width=4cm]{/Users/username/Documents/SP_logo_login.png}}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage} \\ \today , \currenttime}
\fancyfoot[L]{Identification Report \\ User generating the report: {`r paste(user_code)`}}
\vspace*{1\baselineskip}
# IDENTIFICATION REPORT
(some more LaTex and code chunks follow, including bar plots and KableExtra tables)
...
It does not matter wether I put the fancyfoot after some code or right under header-includes. The result is the same. The footer is correctly generated on the first page, but that's all, while the header appears at the beginning of every page.
Any idea on what could be going on?
Your headline is much higher than the default \headheight and therefore pushes the content and the footline off the page. There is an explicit warning in the .log which tells you how height the headline needs to be. The exact value will depend on the aspect ration of your image, for the example image I used, it is about 75pt
---
output:
pdf_document:
keep_tex: true
header-includes:
- \usepackage{fancyhdr}
- \pagestyle{fancy}
- \fancyfoot{}
- \fancyhead{}
- \renewcommand{\headrulewidth}{0pt}
- \geometry{head=75pt, includehead=true, includefoot=true}
---
... (some chunks of code go here)
\fancyhead[L]{\includegraphics[width=4cm]{example-image-duck}}
\fancyfoot[R]{Page \thepage\ of \pageref{LastPage} \\ \today}
\fancyfoot[L]{Identification Report \\ User generating the report: }
\vspace*{1\baselineskip}
# IDENTIFICATION REPORT
(some more LaTex and code chunks follow, including bar plots and KableExtra tables)
...
I have a LaTeX document with a figure and references to it:
\begin{figure}
...
\caption{...}
\label{fig:1}
\end{figure}
\ref{fig:1}
I use the hyperref package to get hyperlinks in the resulting PDF.
However the link to the figure navigates to the caption leaving the figure itself out of the view. How can I make it navigate to the start of the figure instead without moving the caption to the top?
Add this in your preamble
\usepackage{hyperref}
\usepackage[all]{hypcap} %for going to the top of an image when a figure reference is clicked
Make sure that the \usepackage[all]{hypcap} is written after the hyperref package is imported.
To previous comment:
\usepackage{hyperref}
\usepackage{caption}
is slightly better than \usepackage[all]{hypcap} because when you use e.g. figure without captions there won't be a compilation problem. The caption package by default sets option
hypcap=true
anchoring hyperlinks to the beginning of an environment.
\usepackage{hyperref}
\usepackage{caption}
Using this is a better idea than \usepackage[all]{hypcap}.
I have a Latex document where I need to change the margins of only a few pages (the pages where I'm adding a lot of graphics).
In particular, I'd like to change the top margins (\voffset). I've tried doing:
\addtolength{\voffset}{-4cm}
% Insert images here
\addtolength{\voffset}{4cm}
but it didn't work. I've seen references to the geometry package, but I haven't found how to use it for a bunch of pages, and not for the whole document.
Any hints?
Use the "geometry" package and write \newgeometry{left=3cm,bottom=0.1cm} where you want to change your margins. When you want to reset your margins, you write \restoregeometry.
I've used this in beamer, but not for general documents, but it looks like that's what the original hint suggests
\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}
Then to use it
\begin{changemargin}{-1cm}{-1cm}
don't forget to
\end{changemargin}
at the end of the page
I got this from Changing margins “on the fly” in the TeX FAQ.
I was struggling a lot with different solutions including \vspace{-Xmm} on the top and bottom of the page and dealing with warnings and errors. Finally I found this answer:
You can change the margins of just one or more pages and then restore it to its default:
\usepackage{geometry}
...
...
...
\newgeometry{top=5mm, bottom=10mm} % use whatever margins you want for left, right, top and bottom.
...
... %<The contents of enlarged page(s)>
...
\restoregeometry %so it does not affect the rest of the pages.
...
...
...
PS:
1- This can also fix the following warning:
LaTeX Warning: Float too large for page by ...pt on input line ...
2- For more detailed answer look at this.
3- I just found that this is more elaboration on Kevin Chen's answer.
\par\vfill\break % Break Last Page
\advance\vsize by 8cm % Advance page height
\advance\voffset by -4cm % Shift top margin
% Start big page
Some pictures
% End big page
\par\vfill\break % Break the page with different margins
\advance\vsize by -8cm % Return old margings and page height
\advance\voffset by 4cm % Return old margings and page height
For figures you can use the method described here :
http://texblog.net/latex-archive/layout/centering-figure-table/
namely, do something like this:
\begin{figure}[h]
\makebox[\textwidth]{%
\includegraphics[width=1.5\linewidth]{bla.png}
}
\end{figure}
Notice that if you have subfigures in the figure, you'll probably want to enter into paragraph mode inside the box, like so:
\begin{figure}[h]
\makebox[\textwidth]{\parbox{1.5\textwidth}{ %
\centering
\subfigure[]{\includegraphics[width=0.7\textwidth]{a.png}}
\subfigure[]{\includegraphics[width=0.7\textwidth]{b.png}}
\end{figure}
For allowing the figure to be centered in the page, protruding into both margins rather than only the right margin.
This usually does the trick for images. Notice that with this method, the caption of the image will still be in the delimited by the normal margins of the page (which is a good thing).
A slight modification of this to change the \voffset works for me:
\newenvironment{changemargin}[1]{
\begin{list}{}{
\setlength{\voffset}{#1}
}
\item[]}{\end{list}}
And then put your figures in a \begin{changemargin}{-1cm}...\end{changemargin} environment.
Look up \enlargethispage in some LaTeX reference.
I could not find a easy way to set the margin for a single page.
My solution was to use vspace with the number of centimeters of empty space I wanted:
\vspace*{5cm}
I put this command at the beginning of the pages that I wanted to have +5cm of margin.
This worked for me:
\newpage % larger page1
\enlargethispage{1.5cm} % more room for text or floats
\advance\voffset by -0.5cm % reduce top margin
\advance\footskip by 1cm % lower page number
Some content
\newpage % larger page2
\enlargethispage{1.5cm}
Some content
...
\newpage % return to normal page
\advance\voffset by 0.5cm
\advance\footskip by -1cm
I had the same problem in a beamer presentation. For me worked using the columns environment:
\begin{frame}
\begin{columns}
\column{1.2\textwidth}
\begin{figure}
\subfigure{\includegraphics[width=.49\textwidth]{1.png}}
\subfigure{\includegraphics[width=.49\textwidth]{2.png}}
\end{figure}
\end{columns}
\end{frame}