I have a section defined like this:
\section*{\huge Summary}
\label{chap:summary}
And then I use a \ref to it
\nameref{chap:summary}
But the reference also takes the \huge format. How can I remove it?
You should refrain from adding font selections as part of your section title. Instead, rely on packages to manage your formatting. Below I've used secsty to adjust the section font; other options also exist:
\documentclass{article}
\usepackage{sectsty,nameref}
\sectionfont{\huge}
\begin{document}
\section*{Summary}\label{chap:summary}
See section \nameref{chap:summary}.
\end{document}
Related
I declared a new environment containing a \caption and a \label so I can make references to it.
In my header:
\DeclareFloatingEnvironment[name=Tableau]{tableau}
\newenvironment{ptab}{\captionsetup{type=tableau}}{}
In my .tex document:
\begin{ptab}
\caption{A caption for my table}
\label{ptab:myTab}
\end{ptab}
Some text with a reference (Tableau~\ref{ptab:myTab}) % Works fine !
The problem: I want to gain some time by declaring a \newcommand that could write this for me. But the references in text are not working anymore !
Added in my header:
\newcommand{\tabref}[2]{%
\begin{ptab}
\label{#1}
\caption{#2}
\end{ptab}}
In the .tex document:
\tabref{ptab:myTab}{A caption for my table}
Some text with a reference (Tableau~\ref{ptab:myTab}) % Not working "(Tableau ??)"
I an aware a similar question has already been asked before but it was not concerning new environment.
How to reference a label within a newcommand in LATEX?
I found out that the order of \label{} and \caption{} was inverted.
It is important since LaTeX needs to create a caption before it can be referenced with a label.
Working code :
\newcommand{\tabref}[2]{%
\begin{ptab}
\caption{#2}
\label{#1}
\end{ptab}}
\tabref{ptab:myTab}{A caption for my table}
Some text with a reference (Tableau~\ref{ptab:myTab}) % Now working !
We are exploring the features of Sphinx in order to rebuild our legacy manuals. We already ported most of the former manual to Sphinx. Now I'm exploring the possibilities to adapt our company styles.
Especially, we would like to change the appearance of the headers and footers in the PDF manual. Including a company logo and changing the appearance of even and odd pages.
Hence, I included the following preamble in my conf.py with a custom pagestyle using the package fancyhdr.
latex_elements = {
'preamble' : '''\
\\pagestyle{fancy}
\\fancyhf{}
\\fancyhead[LE,RO]{My Header}'''
}
Unfortunately, the headers only changes before begin{document}, afterwards the Sphinx Style File sphinx.sty overwrites somehow my settings.
The following snippet from sphinx.sty might cause the issue:
% Redefine the 'normal' header/footer style when using "fancyhdr" package:
\spx#ifundefined{fancyhf}{}{
% Use \pagestyle{normal} as the primary pagestyle for text.
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py#HeaderFamily\thepage}}
\fancyfoot[LO]{{\py#HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py#HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py#HeaderFamily \#title, \py#release}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
% define chaptermark with \#chappos when \#chappos is available for Japanese
\spx#ifundefined{#chappos}{}
{\def\chaptermark##1{\markboth{\#chapapp\space\thechapter\space\#chappos\space ##1}{}}}
}
% Update the plain style so we get the page number & footer line,
% but not a chapter or section title. This is to keep the first
% page of a chapter and the blank page between chapters `clean.'
\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py#HeaderFamily\thepage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0.4pt}
}
}
What might be a possible workaround?
The table of contents code (in sphinxmanual.cls) ends up with
\ifdefined\fancyhf\pagestyle{normal}\fi
The comment in sphinx.sty says:
% Use \pagestyle{normal} as the primary pagestyle for text.
Thus the simplest should be for your conf.py setting to overwrite the \fancypagestyle{normal}, just re-issue it to your liking.
You will need to wrap the whole latex in \makeatletter...\makeatother if you use \py#HeaderFamily. And use Python raw strings to avoid having to double all backslashes.
in details, here I copy the original definition to conf.py so that it can be customized from there
latex_elements = {
'preamble': """
\makeatletter
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[LE,RO]{{\py#HeaderFamily\thepage}}
\fancyfoot[LO]{{\py#HeaderFamily\nouppercase{\rightmark}}}
\fancyfoot[RE]{{\py#HeaderFamily\nouppercase{\leftmark}}}
\fancyhead[LE,RO]{{\py#HeaderFamily \#title, \py#release}}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
% define chaptermark with \#chappos when \#chappos is available for Japanese
\spx#ifundefined{#chappos}{}
{\def\chaptermark##1{\markboth{\#chapapp\space\thechapter\space\#chappos\space ##1}{}}}
}
\makeatother
""",
}
I have a LaTeX document like this:
\documentclass{article}
\begin{document}
\section{1}
\section{2}
\section{3}
\section{4}
\section{5}
\section{6}
\section{7}
\section{8}
\section{9}
\section{10}
\section{11}
\section{12}
\section{13}
\section{14}
\section{15}
\section{16}
\section{17}
\section{18}
\section{19}
\section{20}
\section{21}
\section{22}
\section{23}
\section{24}
\section{25}
\section{26}
\section{27}
\section{28}
\section{29}
\section{30}
\end{document}
Lots of section headings, but no text in
It produces something like this:
As you can see it keeps all the section headings on one page, and won't break it into 2 pages. Everything above 26 has disappeared off the end of the page.
Is there anyway to get LaTeX to split these sections across multiple pages? I can't easily change the actual content of body, since it's autogenerated. I can change the preamble though. Is there anyway to do this by changing the preamble?
Adding \mbox{} after a section heading would allow the page break. You could introduce it globally in the preamble by:
\makeatletter
\g#addto#macro\#afterheading{\mbox{}}
\makeatother
or
\makeatletter
\expandafter\def\expandafter\#afterheading\expandafter{\#afterheading\mbox{}}
\makeatother
like in this expandafter example.
You should be able to do something like this with the sectsty package
I'm trying to create a new environment in my LaTeX document where indentation in the next paragraph following the environment is suppressed.
I have been told (TeXbook and LaTeX source) that by setting \everypar to {\setbox0\lastbox}, the TeX typesetter will execute this at the beginning of the next paragraph and thus remove the indentation:
\everypar{\setbox0\lastbox}
So this is what I do, but to no effect (following paragraph is still indented):
\newenvironment{example}
{\begin{list}
{}
{\setlength\leftmargin{2em}}}
{\end{list}\everypar{\setbox0\lastbox}}
I have studied LaTeX's internals as well as I could manage. It seems that the \end routine says \endgroup and \par at some point, which may be the reason LaTeX ignores my \everypar setting. \global doesn't help either. I know about \noindent but want to do this automatically.
Example document fragment:
This is paragraph text. This is paragraph text, too.
\begin{example}
\item This is the first item in the list.
\item This is the second item in the list.
\end{example}
This is more paragraph text. I don't want this indented, please.
Internal routines and switches of interest seem to be \#endpetrue, \#endparenv and others. Thanks for your help.
I couldn't get anything to work without redefining \end, but I'm certainly no expert.
The following is quite hacky, but worked in my limited testing. Of course this will interfere with nested environments (you should be able to redefine \begin to restore the old \end if you have problems).
\newenvironment{example}{%
\bgroup
\let\oldend=\end
\def\end##1{\oldend{##1}\csname #afterindentfalse\endcsname
\csname #afterheading\endcsname}
\begin{list}{}
{\setlength\leftmargin{2em}}
}{%
\end{list}
\egroup
}
Can't you avoid this by not having a blank line between your environment and the next line?
This is paragraph text. This is paragraph text, too.
\begin{example}
\item This is the first item in the list.
\item This is the second item in the list.
\end{example}
% (No blank line)
This is more paragraph text. I don't want this indented, please.
Something as simple as this works for me:
\makeatletter
\newenvironment{example}{%
\bgroup
\list{}{}
}{%
\endlist
\#afterindentfalse
\#afterheading
\egroup
}
\makeatother
But, it doesn't work before the first \section (or \chapter, in the case of classes "book" and "report") is called. I don't know why.
I tried the Ivan's answer, but it wasn't working for me. But I did get it working! Here's what I did:
\makeatletter
\renewenvironment{quotation}{%
\bgroup%
\let\oldend=\end%
\def\end##1{\oldend{##1}\csname #afterindentfalse\endcsname%
\csname #afterheading\endcsname}%
\list{}{\listparindent 1.5em%
\itemindent \listparindent%
\leftmargin 1.5em% This controls the size of the indentation
\rightmargin \leftmargin
\parsep \z# \#plus\p#}% This line reduces inter-paragraph space to normal values.
\item\relax%
}{%
\endlist%%
\egroup%
}
\makeatother
The advantage to this is that it typesets your blockquotes very nicely, and removes the indentation from paragraph after the blockquote.
You can do this without redefining \end
\makeatletter
\newenvironment{example}
{\begin{list}
{}
{\setlength\leftmargin{2em}}}
{\end{list}%
\def\if#endpe{%
\#doendpe
\let\par\##par
\iffalse}}
\makeatother
Explanation
\end changes \everypar after expanding \endexample. To make things even more complicated it sets \par to restore \everypar{}. Appearently \#doendpe is ment to make sure that there is no indentation if the paragraph continues after the environment, but to restore normal behavior if there is a \par (or empty line) after the environment.
You may want to avoid changing \end because it would have to be changed at the begining of the environment and may therefore disturb nested environments. Luckily the definition of \end contains \expandafter\endgroup\if#endpe. We can use \if#endpe as a hook to inject our code to the outer scope. After the \endgroup \if#endpe is automatically restored.
Include \#afterindentfalse\#afterheading at the end of your definition.
I had the same problem. I just used this:
\noindent \newenvironment
You should not mess with the \everypar token list, unless you know exactly what you are doing. Use
\setlength{\parindent}{0pt}
to get rid of indenting in the whole document.
ending your environment with \noindent could help you
This stems out of How can one number paragraphs in LaTeX?, which I asked earlier today:
Running with Brent.Longborough's suggestion for how to number paragraphs in a document:
\setcounter{secnumdepth}{5}
...
\paragraph{If we want to}
\paragraph{do something}
This results in LaTeX producing something likeso:
0.0.0.1 If we want to
0.0.0.2 do something
How can one change the numbering scheme of \paragraph{} to produce something like:
1. If we want to
2. do something
or alternatively
A. If we want to
B. do something
Thank you.
To change the number referenced when referring to paragraphs, you want to change \theparagraph. Here's an example:
\documentclass[12pt]{article}
\setcounter{secnumdepth}{5}
\renewcommand\theparagraph{\roman{paragraph}}
\usepackage{lipsum}
\begin{document}
\paragraph{foo} \lipsum[1]
\paragraph{bar} \lipsum[2]
\end{document}
Instead of \roman you can also use \Roman, \arabic, \alph, \Alph. Although if you have lots of paragraphs you'll want to use the alphalph package and use \alphalph to get more than 26 paragraphs.
Note that \paragraph takes an argument for the "paragraph title". If you never want that, you'll probably want to define your own command to simplify things:
\newcommand\PARA{\paragraph{}}
You'll also probably want to remove the way that paragraphs are numbered "within" sections; i.e., they reset from "1" for every new section. You can get around this with something like
\usepackage{remreset}
\makeatletter
\#removefromreset{paragraph}{section}
\makeatother