Redefining sectioning commands in latex, issues with references and labels - latex

I'm trying to change the appearance of one of the native sectioning commands in LaTeX. But after doing so, latex cannot handle references as expected.
The code given later is expected to output a document with the text
1 One
See section 2.
2 Two
See section 1.
But instead I get the following.
1 One
See section .
2 Two
See section .
What can I change in the renewed command, such that the references will work again.
The code for the document is as follows:
\documentclass{article}
\newcounter{seccnt}
\renewcommand{\section}[1]{\vspace{2em}\stepcounter{seccnt} \theseccnt~ {\Large #1}\vspace{0.5em}}
\begin{document}
\section{One}
\label{secOne}
See section \ref{secTwo}.
\section{Two}
\label{secTwo}
See section \ref{secOne}.
\end{document}

I think you need to use \refstepcounter instead of \stepcounter, so that the reference is stored.

Related

Latex ClassicThesis - The numbering of the paragraphs does not appear

I need one more numbered level for my report. I used \paragraph{title} but it only appears without numbering.
In the config file, the paragraph is described as:
\titleformat{\paragraph}[runin]
{\normalfont\normalsize}{\theparagraph}{0pt}{\spacedlowsmallcaps}
I believe that the command \theparagraph is responsible for the numbering. Why doesn't it appear?
I searched the net for answers and tried the following commands (at once) before the beginning of the document:
\setcounter{secnumdepth}{\paragraphnumdepth}
Replace the previous command to get rid of run-in with:
\titleformat{\paragraph}
{\relax}{\textsc{\MakeTextLowercase{\theparagraph}}}{1em}{\normalsize\itshape}
\renewcommand{\theparagraph}{\thesubsection.\arabic{paragraph}}
I put the last two commands in \makeatletter and \makeatother.
The paragraph name appears like the section names now, but still no numbers. Any ideas? Here is a small example that works because I didn't include the classicthesis config files.
\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\setcounter{secnumdepth}{\paragraphnumdepth}
\begin{document}
\chapter{Chapitre}
\section{Introduction}
\subsection{Première sous-partie}
\subsubsection{Un cran en dessous}
\paragraph{Paragraphe with number: what I would like in my report}
Functional here because the problem clearly comes from the two classicthesis config files...
\end{document}
Thank you

How to automatic break lines in latex?

I have searched but nothing useless, only "use \newline" or "use \".
I'm creating a simple latex document to store any texts instead of using .txt, and the problem is that the pdf document contains the lines going towards right until they go out of the paper.
I'm using this simple code
\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=5mm,
top=20mm,
}
\begin{document}
\section{Text 1}
Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemporincididuntutlabore etdoloremagnaaliqua.Utenimadminimveniam,quisnostrudexercitationullamcolaborisnisiutaliquipexeacommodoconsequat.Duisauteiruredolorinreprehenderitinvoluptatevelitessecillum doloreeufugiatnullapariatur.Excepteursintoccaecatcupidatatnonproident,suntinculpaquiofficiadeseruntmollitanimidestlaborum.
\end{document}
Since latex sees it as a one word, it refuses to break it since it doenst know its hyphenation. But I would like to allow latex to break it regardless. Any thoughts ?
Remarks: I already have used:
\hspace{0pt}
\leavevmode\nobreak\hspace{0pt}
\mbox{Loremip...larorum.}
Nothing worked.
I think I got why nothing worked. See my code below, that I managed to compile successfully after editing your MWE.
You basically have two ways to force hyphenation here.
As in the comment by SamCarter, you manually split words within text, just using \- where necessary. I did it below in line 18 (6 from bottom).
You add to your preamble the command \hyphenation{word-to-split}: I did this below to hyphenate the word in line 20 (4 from bottom). Notice that, in this case, you use - instead of \- within the braces {} enclosing the argument.
\documentclass[a4paper]{article}
\usepackage{geometry}
\geometry{
a4paper,
total={170mm,257mm},
left=5mm,
top=20mm,
}
\hyphenation{Duisauteiruredolorinre-prehenderitinvoluptatevelitesse-cillum doloreeufugiatnullapariatur}
\begin{document}
\section{Text 1}
Loremipsumdolorsitamet, consecteturadipiscingelit,
seddoeiusmodtemporincididuntutlaboreetdoloremagna.
Uten\-imadminimveniam,
quisnostrudexercitationullamcolaborisnisiutaliquipexeacommodoconsequat.
Duisauteiruredolorinreprehenderitinvoluptatevelitessecillumdoloreeufugiatnullapariatur.
Excepteursintoccaecatcupidatatnonproident,
suntinculpaquiofficiadeseruntmollitanimidestlaborum.
\end{document}
Finally, if the full stop character . is not followed by a space, two separate words may be interpreted as one and the command \hyphenation may not work as expected. Not sure that this was the detail making you write that nothing worked, but be careful to this too.

How to left align a whole table in markdown (pandoc)?

How do you left align an entire table in Markdown/Pandoc? I know about different ways of specifying tables and how alignment of columns are done, but I cannot find a way to shift the table from center aligned to left aligned (have even tryed embedding <div style="float: left>..</div> which didn't work). Do I have to switch to LaTeX to do this? I will export to pdf later on, if that makes a difference.
I now found a solution to this problem at tex.stackexchange.com. Apparently pandoc inserts \centering for every float in the document. This can be cancelled by inserting \let\centering\relax in a custom preample to pandoc (as pandoc argument -H custompreample.tex). The link also describes more detailed ways to for example define different floats for tables and figures.
I've found this solution here.
a simple \usepackage in header-includes: that looks doing the job itself...
- \usepackage[margins=raggedright]{floatrow}
I hope it won't have side effects. Currently, on my pandoc generated pdfs, none, but I don't know its boundaries.
it has at least one limit: it applies upon every table of your pdf, and not a single one, if it's what you were looking for.
I was not able to get the solutions here to work--in LaTeX. I created a new longtable environment to make tables the way I wanted them. That was easier in the end. Here's an example Rmd file.
---
title: "Custom table"
header-includes:
- \usepackage{longtable,booktabs}
output: pdf_document
---
\newenvironment{mylong}
{\begin{longtable}[l]{p{.25in}p{3in}p{3in}}Line & Statements & Reasons\\
\toprule\addlinespace }
{ \addlinespace\bottomrule\end{longtable} }
\begin{mylong}
1& $a+b=a+d$ & Given P10, if $b=d$, then 1 is true\\
2& $a+b=c$ & Given\\
3& $a+d=c$ & Given P9, if 1 and 2 are true, then 3 is true. QED\\
\end{mylong}

Including a decimal in a Latex section number

I'm trying to get my latex sections to be labeled 1.0, 2.0 instead of 1, 2. Is there an easy way to do this or some way to define the specific numbers I want sections to be numbered?
EDIT:
I have this basic outline:
\documentclass[12pt]{article}
\begin{document}
\section{first}
\subsection{second}
\end{document}
I currently see:
1 first
1.1 second
I would like:
1.0 first
1.1 second
This should do the trick for you. Add the following lines to the preamble:
\renewcommand*\thesection{\arabic{section}.0}
\renewcommand*\thesubsection{\arabic{section}.\arabic{subsection}}
EDIT:
Changed from document type book to document type article. i.e. chapter replaced with section and section replaced with subsection.
EDIT:
Thanks for pointing out the \arabic command! I edited my answer accordingly.

Custom appendix in Latex

I'm Trying to solve a little problem that I have with a book I'm writing, I was wondering if could you give me a hand with my work.
I'm trying to rename the automatic captions in the appendix's tables
that I have. By default Latex do this:
Appendix A:
Table A.1
Table A.2
.
.
Appendix B:
Table B.1
Table B.2
.
.
The problem is: I have 6 chapters in my book, but each chapter except
the first one have appendices and All appendix go in the end of the
book. And All tables and figures in the appendix are A not B or C,
like this:
Anexo 2 <- The renamed appendix 2
Table A2_1
Table A2_2
Table A2_3
.
.
Anexo 3
Table A3_1
Table A3_2
Table A3_3
.
.
Could you help me??? I'll appreciate it so much
Thanks,
Dennis
Firstly, to change 'appendix' to 'Anexo',
\renewcommand{\appendixname}{Anexo}
The \appendix command changes the way sectional units are numbered. I too have found the \appendix command sometimes causes problems since everything which follows it is treated as part of the appendix.
You can create a section labelled 'Appendix' with distinctive numbering by using the \section command with suitably redefined commands for the counters. The following example generates a single 'Appendix' with equations numbered A-1, A-2, ...
\renewcommand{\theequation}{A-\arabic{equation}}
% redefine the command that creates the equation no.
\setcounter{equation}{0} % reset counter
\section*{APPENDIX} % use *-form to suppress numbering
With several appendices you can get appropriate numbering by redefining the \thesection command and resetting the section counter.
Look into the appendix package and its appendices environment. For localized names, look into the babel package instead.

Resources