0

Sorry if this seems blatant and obvious, but I'm only beginning my adventure with LaTeX and I've run into a problem to which I cannot find a solution even among the existing questions.

I need first four paragraphs of a document included in a ToC but they get indented and I'd like them aligned to the left, just like the first section of my thesis. I added them explicitly with the following commands:

\setcounter{tocdepth}{5}
\tableofcontents
\addtocontents{toc}{~\hfill\textbf{Strona}\par}
\addcontentsline{toc}{paragraph}{Streszczenie}
\addcontentsline{toc}{paragraph}{Abstract}
\addtocontents{toc}{\vspace{\normalbaselineskip}}
\addcontentsline{toc}{paragraph}{Słowa kluczowe}
\addcontentsline{toc}{paragraph}{Keywords}
\addcontentsline{toc}{section}{Podziękowania}

I have read that one can use tocloft package and the \cftsetindents command to set indentation of specific elements of the document. Is there a way to explicitly set indentation in toc for certain elements, like those 4 paragraphs in the beginning? I cannot seem to find anything that would demonstrate such option. From my code I get something like this: enter image description here

but I need something like this: enter image description here

I'd be very grateful for some hints and solutions. The \documentclass I use is article.

  • How about \addcontentsline{toc}{section}{Abstract}? It'll put the text in bold, but its the paragraph specifier that's causing indentation. – rbrignall Jun 23 '18 at 11:04
  • @RobertBrignall Yup, this sloved the indentation problem but bold text remains and it introduces spacing in the toc equal to that of sections. Not an optimal solution but will do for now. Thanks! – Krzysztof Czarnecki Jun 23 '18 at 12:55
2

Unfortunaly there is no MWE in the question. So we do not know which class is used and if you load a package like tocbasic, tocloft etc. Nevertheless the following should work:

\documentclass{article}
\usepackage[T1]{fontenc}

\makeatletter
\newcommand\l@myparagraph{\@dottedtocline{5}{0em}{0em}}
\makeatother

\setcounter{tocdepth}{5}

\usepackage{blindtext}% only for dummy text
\begin{document}
\tableofcontents
\addtocontents{toc}{~\hfill\textbf{Strona}\par}
\addcontentsline{toc}{myparagraph}{Streszczenie}
\addcontentsline{toc}{myparagraph}{Abstract}
\addtocontents{toc}{\vspace{\normalbaselineskip}}
\addcontentsline{toc}{myparagraph}{Słowa kluczowe}
\addcontentsline{toc}{myparagraph}{Keywords}
\addcontentsline{toc}{section}{Podziękowania}


\Blinddocument
\end{document}

Result:

enter image description here

  • Thanks, this solved the problem altogether! Next time I run into trouble I'll include a full MWE ;) – Krzysztof Czarnecki Jun 30 '18 at 12:15
1

I think it's better to abuse \part instead of \paragraph.

\documentclass[a4paper,twoside]{article}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc} % not necessary for LaTeX 2018-04-01
\usepackage[english,polish]{babel}
\usepackage{tocloft}

\providecommand{\keywordsname}{}
\addto\captionsenglish{\renewcommand{\keywordsname}{Keywords}}
\addto\captionspolish{\renewcommand{\keywordsname}{Słowa kluczowe}}

\newcommand{\frontsection}[1]{%
  \paragraph*{#1}%
  \addcontentsline{toc}{part}{#1}%
}
% abuse part
\setlength{\cftbeforepartskip}{0pt}
\renewcommand{\cftpartfont}{\normalfont\normalsize}
\renewcommand{\cftpartpagefont}{\normalfont\normalsize}
\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}}

\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}


\begin{document}

This should be the title page
\clearpage

\tableofcontents
\addtocontents{toc}{\protect\mbox{}\hfill\textbf{Strona}\par}
\clearpage

\frontsection{\abstractname}
Streszczenie w języku polskim.

\begin{otherlanguage}{english}
\frontsection{\abstractname}
An abstract in English.
\end{otherlanguage}

\frontsection{\keywordsname}
Słowa kluczowe w języku polskim

\begin{otherlanguage}{english}
\frontsection{\keywordsname}
Keywords in English.
\end{otherlanguage}

\section*{Podziękowania}
\addcontentsline{toc}{section}{Podziękowania}

\clearpage

\section{Wstęp}

\end{document}

enter image description here

  • This also works but I don't quite understand why abusing \paragraph is a bad thing. – Krzysztof Czarnecki Jun 30 '18 at 12:17
  • @KrzysztofCzarnecki Because you need to set secnumdepth to a high value – egreg Jun 30 '18 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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