hide an entry from Toc in latex - latex

I would like to know how I can hide a section from the table of contents but without loosing the section number in the body of the document. For example, in this tex file I loose the number for hide, and all the sequences are damaged:
\documentclass{article}
\begin{document}
\tableofcontents
\section{uno}
\section{dos}
\section*{hide}
\section{tres}
\end{document}

I think you are looking for
\section*{hide}
\addtocounter{section}{1}
or make it into a command:
\newcommand{\toclesssection}[1]{\section*{#1}\addtocounter{section}{1}}
EDIT:
Okay, I think I understand what is wanted now (and it makes more sense then the answer I gave). Here is a command that you can use to suppress adding a section, subsection, etc. to the TOC. The idea is to temporarily disable \addcontentsline.
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
...
\tocless\section{hide}
\tocless\subsection{subhide}

Just wanted to say thanks for Ivans great hint!
(I was just googling for something similar for my customized (Sub)Appendix{} commands:
\newcommand{\nocontentsline}[3]{}
\newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
\newcommand{\Appendix}[1]{
\refstepcounter{section}
\section*{Appendix \thesection:\hspace*{1.5ex} #1}
\addcontentsline{toc}{section}{Appendix \thesection}
}
\newcommand{\SubAppendix}[1]{\tocless\subsection{#1}}
Maybe this is useful for someone else, too...)

have just come here from a similar question. The answer above didn't quite work as it gave some formatting issues, but a similar solution seemed to do the trick

Related

no automatically word wrap with bibliography

I have a problem with my biblatex. My booktitles don't automaticly break lines in my bibliography. Has someone got a hint how to solve this? Is it possible to get an automatic break or do I have to set them manually? And if I so, how do I do that?
Here my biblatex code snippets:
\usepackage[backend=biber,style=authoryear,sorting=nyt,citestyle=authoryear]{biblatex}
\printbibliography[type=book,title={Books}]
See this example at IEEE: after Metrics is a linebreak is missing.
EDIT: I found the solution here
I was curious about the \emph{} style (mine was always underlining). I put a single \normalem in front of the \printbibliography command and it works fine :)
\normalem
\printbibliography[type=book,title={Books}]
Your book titles are underlined, which is preventing line breaks (underlined text doesn't break). I don't think this is a standard behavior, book titles are usually displayed in italics. Perhaps you are using \underline{} inside your bibliography items definitions?

Why Bibliography and References appears in Latex TOC?

I am using these commands for including references:
\addcontentsline{toc}{chapter}{References}
\bibliographystyle{agsm}
\bibliography{dissrefs}
The problem is that in the table of contents both References and Bibliography appear, while I just want one to appear. Why is this happening? Can I customise the table of contents entry to be just one of them?
I am using MikTex 2.8 and TexMaker 2.1.
I dont think that you need to use \addcontentsline{toc} bibtex should do it automatically. At least I don't recall ever needing it...
Have you tried commenting out that line?
Edit regarding OPs comment on changing the title of the bibliography:
The bibliography's title can be changed by (to for instance "New Title") using \renewcommand\refname{New Title} for articles and \renewcommand\bibname{New Title} for books.
Instructions are read and processed in the order they appear, I think your problem is related to that order. Try moving things around (I believe that all settings should be put before \tableofcontents, but I'm not sure about that, I'v not used latex for a long time)

Figure spanning full width of page in two-column article

In a IEEEtran latex template, I am trying to put a figure spanning full width of the page.
I am doing,
\begin{figure*}[h]
\centering
\setlength\fboxsep{0pt}
\setlength\fboxrule{0.25pt}
\fbox{\includegraphics[width=6.2in]{Figure7}}
\caption{Figure}
\label{f7}
\end{figure*}
This places the image on a new page at the end of the article. How do I place it where it should be?
Thanks
For starters I might try to put the figure* block further up in the document, just to check that LaTeX isn't placing it there for a logical reason.
If that doesn't work, I would remove all extraneous commands in the figure* block to be sure they aren't causing problems.
Finally I might try using a figure that doesn't need resizing, or use [width=0.9\linewidth] just to check; sometimes figures that are "too big" can get bumped to the end of the document.
Edit: You may also try using (temporarily) a different template. For example I know that revtex4-1 has a figure* environment that behaves the way to want, to check if ieeetran is the problem or perhaps if that is part of their style.
the problem is the [h].
get rid of that, it'll work.

URL latex linebreak

When a URL is over a line and goes onto a second line, the hyperlink only uses the first line. Is there a way to get around this and yet still have the URL on multiple lines?
You should use the url package:
\usepackage{url}
...
\url{http://long.url.com/... .../stuff}
and it will break it for you at an appropriate place.
I suggest using package:
\usepackage{xurl}
This works fine for me on overleaf.
Example:
\url{https://www.tudelft.nl/ewi/over-de-faculteit/afdelingen/intelligent-systems/pattern-recognition-bioinformatics/pattern-recognition-laboratory/data-and-software/dd-tools/}
At the preamble, just put \usepackage{breakurl} somewhere after \usepackage{hyperref}. The \burl command is defined and, by default, the package also turns the \url command into a synonym of \burl.
Do it the following way. You are good to go!
\begin{document}
\sloppy
For me only this worked:
\PassOptionsToPackage{hyphens}{url}
\usepackage{hyperref}
and with this code to add line breaks after every normal alphabetic character and with *-~'":
\expandafter\def\expandafter\UrlBreaks\expandafter{\UrlBreaks% save the current one
\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
\do\Y\do\Z\do\*\do\-\do\~\do\'\do\"\do\-}%
answer complited from this site:
https://tex.stackexchange.com/questions/3033/forcing-linebreaks-in-url/10401
What packages (hyperref,url) and drivers (pdftex, dvips, etc.) are you using? Are you using the breaklinks option to hyperref?
According to the TeX FAQ you might want to try the breakurl package, though it appears you may simply be out of luck in some cases.
What worked best for me (with pdflatex) was
\usepackage[pdftex]{hyperref}
and then just \url{http://stackoverflow.com/} to create URLs. It only broke URLs at . and /, which was okay for my document. Importantly, other approaches I tried created PDFs where only the first line of the URL was a clickable link, and the destination URL was truncated to this portion, which is pretty confusing and bad.
Long URLs that contain underscores (_) in path segments will not be broken when using \PassOptionsToPackage{hyphens}{url}\usepackage{hyperref}. However, I found that I could solve this problem by manually breaking lines in the displayed label using \\\\, like this:
\href{http://www.researchgate.net/profile/Nick\_Brooks2/publication/220012411\_Cultural\_responses\_to\_aridity\_in\_the\_Middle\_Holocene\_and\_increased\_social\_complexity/links/0922b4f398ad68bc96000000.pdf}{http://www.researchgate.net/profile/Nick\_Brooks2/publication/220012411\_\\Cultural\_responses\_to\_aridity\_in\_the\_Middle\_Holocene\_and\_increased\_social\_\\complexity/links/0922b4f398ad68bc96000000.pdf}
This results in URLs that are a bit prettier (IMO) than the use of \usepackage{breakurl} and \burl, as suggested by Debajyoti Mondal, and allows you to display the full URL if you wish.
There is a simple answer. Use \usepackage[hidelinks]{hyperref} before \begin{document}

How to force line wrapping in listings package?

I have a problem concerning the listings package in latex. I need to embed a source code of the following XML document http://www.sparxsystems.com.au/downloads/profiles/EP_Extensions.xml in my master thesis' appendix. The problem is, no matter what options I pass to the package, I don't seem to be able to fit it on the page. The lines in the listing are too long, and the listings package doesn't wrap them, which seems odd... What combination of options will do the trick?
At the moment I use the following lstset instruction:
\lstset{
breakindent=0em,
language=XML,
basicstyle=\footnotesize,
numbers=left,
numberstyle=\footnotesize,
stepnumber=2,
numbersep=5pt,
backgroundcolor=\color{white},
showspaces=false,
showstringspaces=false,
showtabs=false,
frame=single,
tabsize=2,
captionpos=b,
breaklines=true,
breakatwhitespace=true,
breakautoindent=true,
escapeinside={\%*}{*)},
linewidth=\textwidth
}
Which, with no other options set, and combined with the following command:
\lstinputlisting{EP_Extensions.xml}
Lists the given file's source to the following output:
I just had this problem...
breaklines worked for me, though you do need to set it to true - the default is false:
\lstinputlisting[style=Python,
caption=My Class,
label={mine.py},
breaklines=true,
]{../python/mine.py}
is pretty much what I used
I had this problem and this page ranks highly on google so here was the solution for me:
I had the following inclusion: \usepackage[none]{hyphenat} which causes the issue described above. I was using it to fix the problem of latex automatically breaking lines in the middle of a word, which looks really stupid in some circumstances.
After much searching for an alternative to this solution I found nothing suitable and settled for properly broken lines but badly placed hyphenation.
Not a great answer, but one idea is to word wrap the source code before including it. If you're on linux, the command fold can be used for this. Clearly this works best if the text is in a fixed width font, which i would recommend in any case for code listings.
A followup to Aaron's answer. I was using basicstyle=\ttfamily for my listings. I was therefore able to permit line breaking by changing
\usepackage[none]{hyphenat}
to
\usepackage[htt]{hyphenat}
% ^^^
The hyphenat docs describe that the htt option "enables hyphenation of ... text typeset via either \texttt or \ttfamily." In my use case, I didn't see any hyphenation in my listings, but I did get the breaking.

Resources