Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For single line, the content aligned nicely, but that's not the case when the it contains multiple lines. The alignment is odd:

enter image description here

So how can I make them align nicely?

Mimimum Example

\documentclass[10pt,letterpaper]{article}
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry} 
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\setcounter{tocdepth}{3}
\setcounter{secnumdepth}{3}
\usepackage[bookmarksopen,bookmarksdepth=3]{hyperref}
\usepackage{titlesec}
\usepackage{xcolor}

%define new colors
\definecolor{dark-red}{rgb}{0.4,0.15,0.15}
\definecolor{dark-blue}{rgb}{0.15,0.15,0.4}
\definecolor{medium-blue}{rgb}{0,0,0.5}

%set up color for table of contents
\hypersetup{
    colorlinks, linkcolor={medium-blue},
    citecolor={dark-blue}, urlcolor={medium-blue}
}

\usepackage{tocloft}

%preven linebreak between subsection header and its content
\usepackage{titlesec}
\titleformat{\subsection}[runin]{\normalfont\bfseries}{\thesubsection.}{3pt}{}
\titleformat{\section}[runin]{\normalfont\bfseries}{\thesection.}{3pt}{}

\begin{document}

\setlength{\cftsecnumwidth}{8em} % Set numwidth of section
\setlength{\cftsubsecnumwidth}{12em} % Make subsection numwidth the same as section
\setlength{\cftsubsecindent}{\cftsecindent} % Make subsection indent the same as section

\tableofcontents 
\setlength{\parindent}{0pt}
\setlength{\parskip}{1ex}

    \newpage
    \phantomsection
    \section*{Problem 4.}
    \addcontentsline{toc}{section}
    {
        \numberline{Problem 4.}Let $T$ be a tree with $n > 1$ nodes. What is the maximum number of degrees one vertex $T$ can have?
        What his the minimum number of degree one vertex $T$ can have? Justify both answers.
    }
    Something
\end{document}
share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

In this specific example, you need to remove the spurious space contained in your \addcontentsline definition:

\addcontentsline{toc}{section}
{% <------ Required
    \numberline{Problem 4.}Let $T$ be a tree with $n > 1$ nodes. What is the maximum number of degrees one vertex $T$ can have?
    What his the minimum number of degree one vertex $T$ can have? Justify both answers.
}

ToC

Also note that hyperref complains about: "Token not allowed in a PDF string (PDFDocEncoding): removing 'math shift' on input line XXX". This is because of using math content $ $ within the ToC entry, which eventually end up in the PDF bookmarks. To get rid of this, hyperref provides the conditional \texorpdfstring{<tex-string>}{<pdf-string>}. You would use it in the following way:

\addcontentsline{toc}{section}
{% <------ Required
    \numberline{Problem 4.}Let \texorpdfstring{$T$}{T} be a tree with 
    \texorpdfstring{$n>1$}{n>1} nodes. What is the maximum number of degrees 
    one vertex \texorpdfstring{$T$}{T} can have? What his the minimum number 
    of degree one vertex \texorpdfstring{$T$}{T} can have? Justify both answers.
}
share|improve this answer
    
Many thanks for a very quick solution. It works nicely now. I'm surprised how detailed you are, you even noticed the little space of those mathematics symbols ;) Amazing! –  Chan Sep 2 '11 at 4:41
1  
@Chan: You're welcome! If this answered your question, consider accepting it. –  Werner Sep 2 '11 at 5:46
    
Sorry for the late acceptance. Have been busy with school lately. Once again, thanks a lot ;) –  Chan Sep 5 '11 at 19:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.