I am trying to change the title 'Chapter' in appendices into 'Annex' but am unable to do so. I looked up and found the solution as
\renewcommand\appendixname{Annex}
but this does not solve my problem and the title still shows as 'Chapter'.
My guess is it might be because I have changed the titleformat of the chapters (or it might not be because of it....)
If someone could help me with the issue. My code in the preamble looks like:
\usepackage[titletoc]{appendix}
\titleformat{\chapter}[display]
{\normalfont\LARGE\bfseries\center}{Chapter \thechapter}{0.3em}{\LARGE}
\titlespacing*{\chapter}{0pt}{-15pt}{15pt}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{chapter}.\arabic{section}}
\renewcommand{\thetable}{\arabic{chapter}.\arabic{table}}
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}
\titleformat{\section}
{\normalfont\fontsize{14}{10}\bfseries}{\thesection}{1em}{\fontsize{14}{10}}
\renewcommand{\appendixname}{Annex}
\begin{document}
All contents that matters.....
\begin{appendices}
\chapter{Some Annex}
\input{Chapters/Appendix}
\end{appendices}
\end{document}
The problem is that you hardcoded the word Chapter here:
\titleformat{\chapter}[display]
{\normalfont\LARGE\bfseries\center}{Chapter \thechapter}{0.3em}{\LARGE}
To use the right word, regardless of whether you're in the main content or in the appendices, use \chaptertitlename as documented in the titlesec package documentation (page 4):
\chaptertitlename
It defaults to \chaptername except in appendices where it is \appendixname. Use it instead of \chaptername when defining a chapter.
Remember to add {} to make the trailing space significant:
\titleformat{\chapter}[display]
{\normalfont\LARGE\bfseries\center}{\chaptertitlename{} \thechapter}{0.3em}{\LARGE}
Related
I am currently using Beamer and the listing package to pretty-print code into Beamer blocks. So what I'm doing looks like :
\begin{block}{}
\begin{lstlisting}
int foobar(void) { return 0; }
\end{lstlisting}
\end{block}
Now, I find it cumbersome to start the block and lstlisting environments everytime. I'd like to have a simple codeblock environment that just does it:
\begin{codeblock}
int foobar(void) { return 0; }
\end{codeblock}
So, I tried something like :
\lstnewenvironment{codeblock}
{\begin{block}{}}
{\end{block}}
But unfortunately, the Beamer document no longer compiles, with the following error:
! Missing } inserted.
<inserted text>
}
l.178 \end{frame}
?
Is there some way to do this ?
In Problem with creating a newenvironment in LaTeX, Andreas Grech had the same problem, but it could solve it since there was another way to enter/exit the enclosing environment. But in the case of the block Beamer environment, it seems there is no other way than doing \begin{block}...\end{block}.
I had the same problem and could not find a solution for it. My workaround was to use the \lstinputlisting command and have the code in a separate file. That's great if you have real code you want to include. Not so for small examples.
Another workaround is to put the code snipplet into a variable before starting the {frame} environment and then reference it. How to do this is explained in latex-beamer docs. It would also allow you to employ your custom environment/command.
I "solved" this by using the fancyvrb package's \VerbatimOut(See write environmnet body verbatim to a file) to create a temporary file which then can be included with lstinputlisting:
\usepackage{fancyvrb}
\usepackage{listings}
\newenvironment{blocklisting}[1]
{\begingroup\lstset{#1}\VerbatimOut{blocklisting-tmp.txt}}
{\endVerbatimOut\begin{block}{Code}\lstinputlisting{blocklisting-tmp.txt}\end{block}\endgroup}
For some reason i could not make the environment-argument optional, though.
Used like this:
\begin{document}
\begin{frame}[fragile]
\frametitle{Whatever}
\begin{blocklisting}{language=Java, basicstyle=\Huge}
Code
\end{blocklisting}
\begin{blocklisting}{}
Code 2
\end{blocklisting}
\end{frame}
\end{document}
Not the optimal solution, but it works, i guess.
In my document i'm using the package glossaries to create a glossary. Everything works fine except that the is no link between the words in the text and the corresponding entry in my glossary (so you can click the word to be explained and get to the glossary entry).
The most important parts of my document:
%----Header----
...
\usepackage[nonumberlist,acronym,toc,style=altlist]{glossaries}
\usepackage[
colorlinks=true,
pdfborder=0 0 0,
pdfpagelabels,
plainpages=false,
linktocpage=false,
pdfcreator={LaTeX}]{hyperref}
...
%Glossary entries
\newglossaryentry{glos:twitter}{name=Twitter,
description={Mikroblogging-Service.}}
%----Main document----
\begin{document}
\chapter{Introduction}
This text is a normal glossary item: \gls{glos:twitter}.
This text should also link to the glossary item: \glslink{glos:twitter}{Link to Twitter}
but there is no link
...
\printglossary
\end{document}
As you see i'm also using the package hyperref, but there seems to be no mechanism that automatically links words in the main text to the glossary.
I also tried to use \ref and \label, but this doesnt' work when the element that is referred is outside the main document (like my glossary is).
I'm using the makeglossaries-script coming from miktex (calling makeglossaries main on build), but this also doesn't give me a link.
Anyone knows a way to do that? Or maybe i should use another package than glossaries which supports a functionality like that?
I would also appreciate any working examples where this functionality works.
EDIT:
I just got a working minimal example where gls/glslink actually works. Seems like the linking of glossary items interfers with one of the packages im using in my document. Will have to try by adding my packages one by one to the example to see which package is the reason. The example:
\listfiles
\documentclass{article}
\usepackage[
colorlinks=true,
pdfborder=0 0 0,
pdfpagelabels,
plainpages=false,
linktocpage=false,
pdfcreator={LaTeX}]{hyperref}
\usepackage[nonumberlist,acronym,toc,style=altlist,]{glossaries}
\makeglossaries
%Glossary entries
\newglossaryentry{glos:twitter}{name=Twitter,
description={Mikroblogging-Service.}}
%----Main document----
\begin{document}
\chapter{Introduction}
Ein normales Wort aus dem Glossar: \gls{glos:twitter}.
Dieses Wort soll zum Glossar verlinkt werden: \glslink{glos:twitter}{Link to Twitter}
funktioniert aber nicht...
\clearpage
\printglossary
\end{document}
As not mentioned in the extract of my latex-code, in my documentclass, the draft property was set to true. When removing this property or setting it to false, the gls/glslink work fine.
Is there an easy way to have the complete code in a lstlisting environment underlined?
My current solution looks like this, but I'm not really happy with it.
\begin{lstlisting}[mathescape]
$\ul{if(gt(x1, 0)) then} $
...
\end{lstlisting}
Thanks for any tips.
According to page 5 in the user guide (found here):
\lstset{keywordstyle=\underbar}
If you want to underline the entire line (and not only the keywords), the best solution I can come up with is to do something along the lines below:
\usepackage{listings}
\newcommand{\lstul}[1]{\underline{\mbox{\tt #1}}}
\begin{document}
\begin{lstlisting}[mathescape]
$\lstul{if condition}$
$\lstul{statement 1}$
$\lstul{statement 2}$
...
\end{lstlisting}
\end{document}
I am trying to implement this new environment in LaTeX:
\newenvironment{javacode}[2]
{\begin{lstlisting}[language=java, label=#1, caption=#2]}
{\end{lstlisting}}
And then use it like such:
\begin{javacode}{c}{some code}
int x = 5;
\end{javacode}
But I am getting the following error:
Overfull \hbox (6.0pt too wide) in paragraph at lines 6--6
[][][][][][][]
[1] [2]) [3])
*
Can anyone help as regards fixing this problem?
[Update]
I tried it doing it like Red-nosed unicorn instructed, and it worked correctly.
But now I tried adding a \begin{singlespace} like such:
\lstnewenvironment{javacode}[2]
{
\begin{singlespace}
\lstset{language=java, label=#1, caption=#2}}
{
\end{singlespace}
}
And I got the same error:
Overfull \hbox (6.0pt too wide) in paragraph at lines 6--6
[][][][][][][]
[1]) [2] [3])
*
This is a special case because the listings environment needs to parse ahead itself to find the end of itself. The reason is that macros inside the listings environment must not get expanded – that of course includes the end tag of the environment.
So basically it looks in each line if the line contains \end{lstlisting} – but in your case, no such line exists since the \end{javacode} macro has not yet been expanded. So listings continues to search until the end of the file.
Listings defines an own command to work around this. From the documentation:
\lstnewenvironment
{⟨name⟩}[⟨number⟩][⟨opt. default arg.⟩]
{⟨starting code⟩}
{⟨ending code⟩}
For example:
\lstnewenvironment{javacode}[2]
{\lstset{language=java, label=#1, caption=#2}}
{}
EDIT In response to your edited question: I tried to compile the following minimal “working” example. Actually, it’s not so much working – the latex processor just stops right in the middle and waits for a user input.
Since the listings documentation makes no mention of a special treatment of singlespace, I think you may have uncovered a bug. The best course of action is probably to get feedback from the maintainer of the listings package.
% mini.dvi
\documentclass{article}
\usepackage{listings}
\usepackage{setspace}
\doublespacing
\lstnewenvironment{javacode}
{\begin{singlespace}
\lstset{language=java}}
{\end{singlespace}}
\begin{document}
\begin{javacode}
int a = 1;
int b = 2;
\end{javacode}
\end{document}
Upon further research, I found this http://www.tug.org/pipermail/texhax/2009-June/012699.html
To workaround my solution, I need to use \singlespacing instead of the singlespace environment.
The following is now my working code:
\lstnewenvironment{javacode}[2]
{\singlespacing\lstset{language=java, label=#1, caption=#2}}
{}
I'm trying to turn off marginpar when starting a new multicols environment with this new environment, which uses the multicols and chngpage packages:
\newenvironment{multi}[1]{%
\newlength{\newtextwidth}%
\setlength{\newtextwidth}{\marginparwidth}%
\addtolength{\newtextwidth}{-1cm}%
\addtolength{\headheight}{.5cm}%
\let\oldheadrule\headrule%
\addtolength{\headwidth}{\newtextwidth}%
\begin{adjustwidth}{}{-\newtextwidth}\begin{multicols}{#1}}%
{\end{multicols}\end{adjustwidth}}
Which works great:
latex header http://img6.imageshack.us/img6/6757/screenshotewa.png
Uhm, almost, since on the last page of the current chapter "Lorem ipsum" it behaves like I hadn't instruct it to: \addtolength{\headwidth}{\newtextwidth}:
latex header at the end of the chapter http://img11.imageshack.us/img11/6072/screenshotwbd.png
How could I fix that?
Edit:
I'm also using fancyhdr.
2nd Edit:
A PoC:
\documentclass[12pt,a4paper,oneside]{report}
\usepackage[utf8]{inputenc}
\usepackage[top=2cm,left=2cm,right=4.5cm]{geometry}
\usepackage{chngpage}
\usepackage{color}
\usepackage{amsmath}
\usepackage[pdftex,bookmarks,pdfpagemode=UseOutlines,bookmarksopen,backref
,colorlinks,urlcolor=blue,linktocpage]{hyperref}
\usepackage{url}
\usepackage{amssymb}
\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{indentfirst}
\usepackage{listings}
\usepackage{boxedminipage}
\pagestyle{fancy}
\setlength{\columnseprule}{1pt}
\setlength{\marginparwidth}{4cm}
\rhead{\large\leftmark}
\renewcommand{\chaptermark}[1]{%
\markboth{#1}{}}
\makeatletter
\renewcommand*\#makechapterhead[1]{%
{\parindent \z# \raggedright \normalfont
\huge\bfseries
#1\par\nobreak
\vskip 20\p#
}}
\makeatother
\let\oldmarginpar\marginpar
\renewcommand\marginpar[1]{\-\oldmarginpar[\sffamily\raggedleft\footnotesize #1]%
{\sffamily\raggedright\footnotesize
\begin{boxedminipage}{\marginparwidth}#1\end{boxedminipage}
}}
\newenvironment{multi}[1]{%
\newlength{\newtextwidth}%
\setlength{\newtextwidth}{\marginparwidth}%
\addtolength{\newtextwidth}{-1cm}%
\addtolength{\headheight}{.5cm}%
\let\oldheadrule\headrule%
\addtolength{\headwidth}{\newtextwidth}%
\begin{adjustwidth}{}{-\newtextwidth}\begin{multicols}{#1}}%
{\end{multicols}\end{adjustwidth}}
\begin{document}
\tableofcontents
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\chapter{Lorem ipsum}
\begin{multi}{2}
\lipsum[1-20]
\end{multi}
\end{document}
It should be possible to continue single-column on the same page, after "multi", but the headers must be kept like when the page was started within the "multi" environment.
Why would I need single-column after multi-column on the same page with a marginpar? Imagine presenting the source code for the article, with small hints on the margin. (That's what the listing package is there for)
I suspect your last heading box is being constructed after your text finishes making the multicol boxes, so you're out of the scope of your change. It goes back to the old value.
You'd probably do well to add the fancyhdr package and use it. I believe it's well-behaved in multicolumn.
Okay, so it's almost certainly the scope thing. You're doing the adjustwidth in your new multi environment. When your text runs out in the multi envirnment, you haven't filled the last page; headers aren't set up until the page is filled. So your mutlti environment finishes the box, you leave the scope, and THEN the page is finished and emitted. Using the old width.
Set the header width and parameters outside the environment.
I ran your test document. It seems to have a bug in that \newlength{\newtextwidth} has a global effect, and so causes an error. Not sure why that is but I pulled it out of the \newenvironment{multi} with no ill effect.
Charlie's diagnosis is definitely correct. An alternative solution is to end the page after the multicols but before the adjustwidth, thus:
\newenvironment{multi}[1]{%
...}
{\end{multicols}\vfill\break\end{adjustwidth}}
I have tested this solution and on your sample document, it produces good output.