Missing \item error when centering sections in LaTeX - latex

So I am writing up a worksheet for my students to use and I wanted to just have a few numbered section headers like I have below. However, for some reason, the second set of centered title is returning the error: Something's wrong--perhaps a missing \item. \end{center} at the end of the second \end{center}. Is there some way around this? I have even copy/pasted the first set of centerings just in case it was a syntax error of some sort.
\documentclass[12pt,a4paper]{exam}
\usepackage[latin1]{inputenc}
\usepackage[top=1in, bottom=1in, left=1.25in, right=1.25in]{geometry}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{lscape}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{center}
\section{Solve using substitution}
\end{center}
\blah\blah\blah
\begin{center}
\section{Solve using substitution}
\end{center}
\blah\blah\blah
\end{document}

\begin{center} ... \end{center} should not be used for headers. In my opinion the best option is to use:
\usepackage[center]{titlesec}
P.S. This will center ALL headers in the document, if that is what you were looking for this is the cleanest solution

Related

Footnote in Caption of Figure on latex

Although i have tried many code of a footnote in a caption of a figure , it doesn't work , really , where is the problem here
\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{fancyhdr}
\makenomenclature
\usepackage[nottoc]{tocbibind}
\pagenumbering{Roman}
\usepackage{lipsum}
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{4}
\begin{document}
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth{images/frog.jpg}
\caption[frog]{frog \footnotemark }
\label{fig:pic1}
\end{figure}
\footnotetext{frog}
\end{document}
Two problems:
you can't have the \makenomenclature macro in your code with a package which defines it, e.g. nomencl
the ] after the optional argument of your graphic is missing
With the split between \footnotetext and \footnotemark there is always the risk that the floating figure and the footnote will end up on different pages. You can lessen the risk by using [htbp] as floating specifier for your figure, this way you at least allowed the figure to be placed where the footnote is.
\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{fancyhdr}
%\makenomenclature
\usepackage[nottoc]{tocbibind}
\pagenumbering{Roman}
\usepackage{lipsum}
\setcounter{tocdepth}{5}
\setcounter{secnumdepth}{4}
\begin{document}
\begin{figure}[htpb]
\centering
\includegraphics[width=0.8\textwidth]{example-image-duck}
\caption[frog]{frog \footnotemark }
\label{fig:pic1}
\end{figure}
\footnotetext{frog}
\end{document}

Figure in Latex is not centering despite using \centering

I am very new to LaTex and am trying to center a figure.
I have tried to use the package float using both [h] and [H], I have tried to add \centering and I have tried to wrap the image in \begin{center} \end{centering} but nothing seems to work.
My full code is as such
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}
\graphicspath{ {images/} }
\title{Dissertation}
\author{GC}
\date{\today}
\begin{document}
\maketitle
\section{Introduction}
\begin{figure}[H]
\centering
\includegraphics{my_grades}
\caption{grades plot}
\label{fig:grade}
\end{figure}
This figure does not seem to want to centre
\end{document}
This figure on the compiled document looks as such. If someone could help me understand why this doesn't want to move that would be great:
Your code seems fine, I just added a [width=50mm] in your include graphics and it centered the Figure.
I would check two issues:
Is your figure to larger than the textwidth?
Does your Figure has a white part on its lefthand side?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}
\graphicspath{ {images/} }
\title{Dissertation}
\author{GC}
\date{\today}
\begin{document}
\maketitle
\section{Introduction}
\begin{figure}[H]
\centering
\includegraphics[width=50mm]{darth-vader_5yvm.jpeg}
\caption{grades plot}
\label{fig:grade}
\end{figure}
This figure does not seem to want to centre
\end{document}

Additional dot in section/subsection not being displayed in table of content

I would like to have a table of content with numbering identical to the ones in text. So, in text each section/subsection/subsubsection is numerated as '1.' or '1.1.' or '1.1.1.'. However my table of content is not updating it, so it shows '1' or '1.1'.
I was following answer to this topic: https://superuser.com/questions/811779/how-to-add-a-dot-for-section-subsection-numbering-in-tex
So I am using 'secdot' package. I have tried using
\renewcommand{\thechapter}{\arabic{chapter}.}
\renewcommand{\thesection}{\thechapter\arabic{section}.}
but I keep getting '\the chapter undefined', 'No counter chapter defined' or 'Missing number, treated as zero' errors.
I would appreciate any tips on what's wrong.
EDIT:
\documentclass[11pt, a4paper, twoside]{article}
\usepackage{listings, lstautogobble}
\usepackage{ragged2e}
\usepackage{times}
\usepackage{secdot}
\sectiondot{subsection}
\usepackage{listings}
\usepackage[toc,page]{appendix}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\geometry{a4paper,
left=30mm,
top=25mm,
bottom=25mm,
right=20mm
}
\sectiondot{subsection}
\makenomenclature
\setlength{\parindent}{0.5 cm}
\renewcommand{\baselinestretch}{1.15}
\pagenumbering{roman}
\begin{document}
\setboolean{#twoside}{false}
\begin{figure}[H]
\begin{center}
\includegraphics[width=14cm,height=15cm,keepaspectratio]{./thesis- frontpagedesign}
\end{center}
\end{figure}
\begin{center}
\tableofcontents
\end{center}
\begin{center}
\listoffigures
\end{center}
\section{Introduction}
%sometext
\makeatletter
\def\#seccntformat#1{%
\expandafter\ifx\csname c##1\endcsname\c#section\else
\csname the#1\endcsname\quad
\fi}
\makeatother
\end{document}
Your current setup is confusing. For example,
\makeatletter
\def\#seccntformat#1{%
\expandafter\ifx\csname c##1\endcsname\c#section\else
\csname the#1\endcsname\quad
\fi}
\makeatother
removes the setting of any \section number. And mixing this with the use of secdot seems problematic.
The easiest way to achieve dots after sectional unit numbers within your text as well as the ToC is to adjust the representation of the respective counters:
\documentclass{article}
\renewcommand{\thesection}{\arabic{section}.}
\renewcommand{\thesubsection}{\thesection\arabic{subsection}.}
\renewcommand{\thesubsubsection}{\thesubsection\arabic{subsubsection}.}
\begin{document}
\tableofcontents
\section{Introduction}
\end{document}
This solution is sufficient, but will also affect \references. For example \ref{sec:introduction} would return 1. which may look odd in the middle of a sentence: ... from section~\ref{sec:introduction} we can see ....
If you don't want periods ending your \references, you can use
\usepackage{secdot}% Adds . after sectional unit numbers
\usepackage{etoolbox}
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\numberline}{\hfil}{.\hfil}{}{}
You're already familiar with what secdot does. The patch to \numberline is thanks to etoolbox which changes the default definition
\def\numberline#1{\hb#xt#\#tempdima{#1\hfil}}
into
\def\numberline#1{\hb#xt#\#tempdima{#1.\hfil}}
effectively inserting an ending-period as part of the number that is printed within the ToC. Note that this will also affect how figures/tables are displayed within the LoF/LoT. However, one can change that using scoping:
\begingroup
% The following patch will only affect entries in the ToC
\patchcmd{\numberline}{\hfil}{.\hfil}{}{}
\tableofcontents
\endgroup
\listoffigures
\listoftables

Ruled Text in Textbox with Lines

I'd like to have a function for a "letter". By letter I mean that it is a ruled paper, and the text looks justified, as if it would be without the "uline" function.
Moreover, the ulem package is not what I want, since the last line will always be short (any line that has a linebreak).
I am more thinking of something as in the exam class, the \fillwithlines order.
Anyone has an idea? Thanks in advance!
\documentclass[fontsize=9pt,twoside, DIV=calc]{scrbook}
\usepackage[papersize={12.5cm,19cm},inner=10mm, outer=10mm, bottom=13mm, top=10mm, footskip=6mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[]{lipsum}
\usepackage{xcolor}
\xdefinecolor{notiz}{RGB}{239,227,157}
\usepackage{tabularx}
\usepackage{tikz}
\usepackage{tikzsymbols}
\usepackage{varwidth}
\usetikzlibrary{shapes}
\usetikzlibrary{decorations.pathmorphing}
\usepackage{ulem}
\newcommand{\post}[1]{
\small
\begin{center}
\begin{tikzpicture}[pencildraw/.style={ %
decorate,
decoration={random steps,segment length=2pt,amplitude=1pt}
} %
]
\node[ preaction={fill=black,opacity=.5,% zeilenabstand=2.8,
transform canvas={xshift=1mm,yshift=-1mm}},
pencildraw,draw,fill=notiz,text width=.8\textwidth,
inner sep=5mm] {\uline{#1}};
\end{tikzpicture}
\end{center}
\normalsize
}
\begin{document}
\post{\lipsum[1]}
\end{document}

Vertically centering a title page

I'm trying to vertically center a title on a custom-sized page with latex. I've written the following code, but for some reason it doesn't center. Could someone please point me to what's wrong with it?
Thanks!
\documentclass{article}
\setlength{\pdfpagewidth}{88.184mm}
\setlength{\pdfpageheight}{113.854mm}
\usepackage[margin=0.5cm, paperwidth=88.184mm, paperheight=113.854mm]{geometry}
\title{[[title]]}
\date{[[date]]}
\author{[[author]]}
\begin{document}
\vspace{\fill}
\maketitle
\vspace{\fill}
\newpage
[[text]]
\end{document}
There are two small bugs in your code.
First, if you want the \vspace to work at the beginning or end of a page, you should use the starred version (\vspace*).
This would work, but \maketitle is a pretty complicated macro, and if used like in your example, it just puts the title at the second page. You can use the titlepage environment, which gives you much more command over how the title page looks like -- including the spacing. For example, you could use the following code:
\documentclass{article}
\setlength{\pdfpagewidth}{88.184mm}
\setlength{\pdfpageheight}{113.854mm}
\usepackage[margin=0.5cm, paperwidth=88.184mm, paperheight=113.854mm]{geometry}
\begin{document}
\begin{titlepage}
\vspace*{\fill}
\begin{center}
{Huge [[title]]}\\[0.5cm]
{Large [[author}\\[0.4cm]
[[date]]
\end{center}
\vspace*{\fill}
\end{titlepage}
[[text]]
\end{document}
\null % Empty line
\nointerlineskip % No skip for prev line
\vfill
\let\snewpage \newpage
\let\newpage \relax
\maketitle
\let \newpage \snewpage
\vfill
\break % page break
If you want to make everything work even with \maketitle put your \vspace*{\fill} inside the first and the last attribute, exp:
\title{**\vspace*{\fill}**[[title]]}
\date{[[date]]}
\author{[[author]]**\vspace*{\fill}**[[}
\begin{document}
\maketitle
\newpage
[[text]]
\end{document}
As in the answer by finrod, \maketitle is a pretty complicated macro, this is why I didn't feel like overwriting it myself (\renewcommand\maketitle{...). Nevertheless, copying, pasting and editing lines 170-201 of article.cls documentclass, I could add a new one to customize (\newcommand\mymaketitle{...) as follows:
\documentclass{article}
\setlength{\pdfpagewidth}{88.184mm}
\setlength{\pdfpageheight}{113.854mm}
\usepackage[margin=0.5cm, paperwidth=88.184mm, paperheight=113.854mm]{geometry}
\title{Title}
\date{Date}
\author{Author}
\makeatletter
\newcommand\mymaketitle{%
\begin{titlepage}
\null\vfil\vskip 40\p#
\begin{center}
{\LARGE \#title \par}
\vskip 2.5em
{\large \lineskip .75em \#author \par}
\vskip 1.5em
{\large \#date \par}
\end{center}\par
\#thanks
\vfil\null
\end{titlepage}
}
\makeatother
\begin{document}
\mymaketitle
Text
\end{document}
The output:

Resources