I'm wondering why in my toc shown below, I have different dots style in the most detailed subsections ?
All I've used is:
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
....
\tableofcontents
How can I create a consistent style at all levels of depth: section, subsection, etc?
It really depends on the document class you are using; book, article etc have a preset layout for the TOC.
Since you said you are writing your Thesis, is it possible that you are using a style given by the college/university?
There is still a way to change it. You can use the package tocloft,
\usepackage{tocloft}
which has a method called \#dotsep to change the amount of space between the dots. Although I do not know if it will work in this case as you only define it once for the whole TOC and if it is relative to what you have it may just increase your dots relative to the way it is already placed.
But here is the code anyways,
\makeatletter \renewcommand{\#dotsep}{4.5} \makeatother
\tableofcontents
It must be placed before your toc command and 4.5 represents the distance.
But like I said this depends on your document class and its style class. Here is the link to the package documentation tocloft.pdf. There are more customizations available which may work for you better.
At least in the article class, they already have a standard style, but to also get dot leaders for sections like the ones in subsections, just use this:
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
Related
I am having issues with a report I am writing. First time using latex and after getting some help on here regarding some tables weirdness I again have a silly frustrating issue. Figures don't stay where I put them. I made a MWE Posted Below
\documentclass{article}
\usepackage{graphicx}
\graphicspath{ {./Figures/} }
%%%%%% Referencing %%%%%%
\usepackage{natbib}
\bibliographystyle{abbrvnat}
\setcitestyle{authoryear,open={(},close={)}}
\title{MWE}
\begin{document}
\maketitle
\section{Introduction}
The average sea surface temperature (SST) trend is shown in Figure \ref{fig:SST}.
\section{Figures}
\begin{figure}
\includegraphics[width = \linewidth]{Figures/SST.png}
\label{fig:SST}
\end{figure}
\section{References}
\bibliography{References.bib}
\bibliographystyle{agsm}
\end{document}
I expect, probably an error, for the figure to be inserted under the Figures subheading however it appears on the next page after references. I have to refer to my figure in the text, hence the \ref{fig:SST} so it is clickable. It's not a size issue as there is more than enough space on the page to accommodate the figure. Even if that was the issue I would expect the references subheading to be after it.
Most latex classes use so called floats for figures, tables etc. The idea is that latex will automatically find a good place for your images and avoid ugly white space.
To make use of the abilities of latex to produce a good looking output, you must specify possible placements with floating specifier such as [htbp], which allows latex to place the image here, at the top, at the bottom or an a separate page.
Also if you want to use the \label-\ref mechanism, your figure must have a caption (and the label inside or after the caption).
\documentclass{article}
\usepackage{graphicx}
\graphicspath{ {./Figures/} }
%%%%%% Referencing %%%%%%
\usepackage{natbib}
\bibliographystyle{abbrvnat}
\setcitestyle{authoryear,open={(},close={)}}
\title{MWE}
\begin{document}
\maketitle
\section{Introduction}
The average sea surface temperature (SST) trend is shown in Figure \ref{fig:SST}.
\section{Figures}
\begin{figure}[htbp]
\includegraphics[width = \linewidth]{example-image-duck}
\caption{test}
\label{fig:SST}
\end{figure}
\section{References}
\bibliography{References.bib}
\bibliographystyle{agsm}
\end{document}
Generally, LaTeX's attitude is ‘you write the text, let me worry about placing the figures’.
Floats (that is, figures and tables) will float to where LaTeX thinks they go best. I can't remember the precise rules in the article style, but generally they float to the top of the nearest following page that has room for them. LaTeX won't fill too much of a page with figures, so if you have a dense sequence of large-ish figures, some of them can end up quite a long way away from the point in the source text where they're written.
This is normal, and how figures and tables appear in the majority of published books and articles.
You'll usually write a caption:
\begin{figure}
\includegraphics{...blah...}
\caption{This is a caption for my figure\label{fig:SST}}
\end{figure}
Then you can write
...this is shown in Figure~\ref{fig:SST}
If you want to, you might add ...on p.\thinspace\pageref{fig:SST} and LaTeX will insert the page number where the figure ends up. Also, see the prettyref package.
As mentioned in the other answer, you can add placement specifiers like [ht], which give LaTeX permission to put the figure ‘here’ or at the top of a page, but that doesn't force anything. It is possible to fight with LaTeX about this (the Overleaf docs give some hints), but it's generally not worth it in my experience.
That said, one bit of guidance it's useful to give LaTeX is something like \renewcommand{\floatpagefraction}{.8}, which says that LaTeX is allowed to use as much as 80% of the page for floats (ie, figures and tables) – the default value is a bit tight (there are more comments on this in this TeX.SE question – tex.stackexchange.com is generally a better site for LaTeX-related questions).
If you do feel compelled to fight/fiddle with float placement, do it at the very end of the process, where you're fine-tuning the punctuation of your document. Small changes in the document can have big effects on where floats end up, and it's simply not worth worrying about this until your document is almost finalised.
Your final puzzlement was about the figure ending up after the references. In the case of your document, the figure goes on p.2, so there's plenty of space on p.1 for LaTeX to carry on setting text, so naturally it puts the references there. Since you generally do want the references to go at the very end of an article, this is a case where it's reasonable to exert a little control over placement, and a good idea would be to put \clearpage before the References section. What that does is to make a new page and force out any floats which are still in the queue waiting for space to appear.
I am writing my PhD thesis (120+ pages) in latex, the deadline is approaching and I am struggling with layout problems.
I am using the documentstyle book.
I am posting both problems in this one thread because I am not sure if the solution might be related to both problems or not.
Problems are:
1.) The page numbers are mostly located on the top-right of each page (this is correct and where I want them to be).
However, only on the first page of chapters and on the first page of what I call "special chapters", the page number is located bottom-centered.
With "special chapters" I mean: List of Contents, List of Figures, List of Tables, References, Index.
My university will not accept the thesis like this. The page number must ALWAYS be top-right one each page, even if the page is the first page of a chapter or the first page of something like the List of Contents.
How can I fix this?
2.) On the first page of chapters and "special chapters" (List of Contents...), the chapter title is located far too low on the page. This is the standard layout of LaTeX with documentstyle book I think.
However, the chapter title must start at the very top of the page! I.e. the same height as the normal text on the pages that follow.
I mean the chapter title, not the header.
I.e., if there is a chapter called
"Chapter 1
Dynamics of foobar under mechanical stress"
then that text has to start from the top the page, but right now it starts several centimeters below the top.
How can I fix this?
Have tried all kinds of things to no effect, I'd be very thankful for a solution!
Thanks.
A try to answer
problem #1.
Even if you're using the headings pagestyle, or your custom pagestyle, the special pages (chapter beginnings and so on) are formatted with the plain pagestyle.
To avoid this, load the fancyhdr package (as mentioned in the previous answer) with
\usepackage{fancyhdr}
in your preamble. Then, (always in the preamble) define your custom pagestyle.
For normal pages (assuming you're not using twoside as an option of \documentclass[]{}):
\fancypagestyle{phdthesis}{%
\fancyhf %clear all headers and footers fields
\fancyhead[R]{\thepage} %prints the page number on the right side of the header
}
For special pages:
\fancypagestyle{plain}{%redefining plain pagestyle
\fancyhf %clear all headers and footers fields
\fancyhead[R]{\thepage} %prints the page number on the right side of the header
}
After doing this, you can set you page style declaring \pagestyle{phdthesis} right before \begin{document}.
For further details, refer to the fancyhdr package documentation.
Now trying to answer
problem #2
As a first attempt, you can use the titlesec package, using the option compact. In the preamble, type:
\usepackage[compact]{titlesec}
If you're not completely satisfied with this solution, you can specify the spacing above and below the titles with \titlespacing
\usepackage{titlesec}
\titleformat{ command }[ shape ]{ format }{ label }{ sep }{ before }[ after ]
\titlespacing{ command }{ left }{ beforesep }{ aftersep }[ right ]
With \titleformat you can define your own style for chapter titles, and then you can define the spacing with \titlespacing.
I don't know which style of titles you have to use, so it's better for you to have a look to the package documentation (you can recall package documentation typing texdoc NameOfThePackage in a terminal).
Please note that you need to define the chapter title format in order to specify its vertical spacing (page 5 of the documentation). As an example:
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\huge}{\thechapter}{1em}{}
\titlespacing{\chapter}{0pt}{0pt}{1cm}
With these commands you have the chapter title with the number and the chapter name on the same line, a 0 pt space before the title, and a 1 cm space between the title and the follwing text.
To change the page appearance, you can use the fancyhdr package. It's probably a change in the \pagestyle used for the special chapters.
To change the appearance of the chapter title (to have the chapter title printed from the top on the page, you have to use a modified style that change \chapter command rendering.
Here is an example of command I used for my own thesis. It is probably not the appearance you want but gives you an hint about the command you have to redefine.
% modified from book.ltx latex sources
\def\#makechapterhead#1{%
\thispagestyle{empty}%
\vspace*{50\p#}%
\vspace*{10\p#}%
{\parindent \z# \centering \reset#font
\thickhrulefill\quad
\scshape \#chapapp{} \thechapter
\quad \thickhrulefill
\par\nobreak
\vspace*{10\p#}%
\interlinepenalty\#M
\hrule
\vspace*{10\p#}%
\Huge \bfseries #1\par\nobreak
\par
\vspace*{10\p#}%
\hrule
\vskip 40\p#}}
Regarding problem #2 an alternative without additional packages is to change the vertical offset of the page, and then resetting it to the previous value.
\voffset -1in
\chapter{Your chapter}
% text
\voffset 0in
I just arrived at this page.
It is both simple to implement and looks great.
I'm looking for more such examples.
You already hit a gold mine with texample.
A couple of obvious tips:
The TikZ manual contains all kinds of gorgeous examples of drawing with LaTeX
The beamer homepage contains some beamer examples to demonstrate its power. The beamer manual is also full of examples.
So: texample, TikZ manual, beamer manual. There is no other good resource that I'm aware of for LaTeX presentations.
Update: there is also the Beamer Theme Matrix, for the choice of a beamer theme.
One thing you can do is not use the default colour theme. EVERYBODY uses the blue/white theme. It's boring. So think carefully about using a different theme. That will immediately make your presentation stand out. (unless everyone else is using powerpoint, in which case you already have the upper hand)
For example: \usecolortheme{beaver} will immediately make your presentation look different from other beamer presentations. You might want to add \setbeamercolor{itemize item}{fg=darkred!60!black} or something similar to your preamble so that bullet points are red rather than blue. (I cannot understand how colour themes fail to redefine that by default...) [this trick comes from here
I am looking for a simple way to control the width of a \caption{} inside a float in LaTeX without using the {caption} package. Any clues?
(EDIT): The problem I am having is that the built-in captions are too narrow.
In general, to control the width of objects in TeX, you can use a minipage, for instance:
\begin{minipage}[t]{1.85in}
\caption{ Why would you eat a pickle? }
\end{minipage}
However, with a caption you might need to do something different as it could very well be a macro.
To change the formatting of the standard LaTeX classes without using a package, you need to look at the source of the standard LaTeX classes and alter the original definitions in your own document. Printing captions is done by the macro \#makecaption, which has definition (in article.cls):
\long\def\#makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\#tempboxa{#1: #2}%
\ifdim \wd\#tempboxa >\hsize
#1: #2\par
\else
\global \#minipagefalse
\hb#xt#\hsize{\hfil\box\#tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
If you wrap the whole thing in a minipage environment (as suggested to be done manually in the other answers), you should get the results you want.
Is it easier than loading a package? Not really, but it can be instructive.
There's nothing too magical about \caption; it just consults a figure/table number and than formats your text at a font and size that the document class likes. So you can control its width the same way you'd control the width of any text:
Wrap the \caption{...} in a \parbox or a \begin{minipage}...\end{minipage}.
In LaTeX figures, one can use \textwidth and \columnwidth to specify sizes of the graphic relative to the size of surrounding text, e.g.
\includegraphics[width=.5\textwidth]{myimage}.
I would like to easily switch from onecolumn to twocolumn template (and back) without the figure growing too large for onecolumn template. For twocolumn template (where \columnwidth is roughly half the \textwidth), I would like to have something like:
\includegraphics[width=.9\columnwidth]{myimage}.
and for onecolumn template (where \columnwidth and \textwidth are equal):
\includegraphics[width=.5\textwidth]{myimage}.
Now, I figured I could limit this using some kind of a min operator:
\includegraphics[width=min(.5\textwidth,.9\columnwidth)]{myimage} but this is invalid syntax. Is there something like this to solve this problem, possibly through the use of LaTeX macro system?
Although it's possible to write this sort of macro, I wouldn't want to hardcode it into each figure; how about something like this
\makeatletter
\newlength \figwidth
\if#twocolumn
\setlength \figwidth {0.9\columnwidth}
\else
\setlength \figwidth {0.5\textwidth}
\fi
\makeatother
and then use
\includegraphics[width=\figwidth]{myimage}
to insert the graphic.
\textwidth is the horizontal width of the page body and not really appropriate for your purposes.
\linewidth is the width of the current line; it will be updated appropriate to columns, indentation, etc.
The following paragraph produces a picture that should precisely fit the entire line width (i.e. no overful warning):
\noindent\includegraphics[width=\linewidth]{myimage}
If you prefer small margins on the left and right, you can use:
\begin{center}
\includegraphics[width=.9\linewidth]{myimage}
\end{center}
Or, if you want to specify the margins in an absolute size:
\usepackage{calc}
...
\begin{center}
\includegraphics[width=\linewidth-20pt]{myimage}
\end{center}
Hmm... the code above (\if#twocolumn etc.) is not working for me at all. No idea why not. :( tetex on osX using fink. Trying to use revtex4, so perhaps that's the problem. I really like the idea of this type of change because I'm going to be dorking with widths etc. for my thesis and various journal articles, and to have these distances specified with a macro may be helpful for these types of conversions.
Any comments greatly appreciated!
-Allen
Somebody else who is more familiar with this will probably answer, but note that you would also need to change your figure type to be figure* if you are going two-column.