2

I'm writing a draft of my notes with Latex. They are basically definitions related to a particular concept from different sources. Therefore I have used the command \section to highlight the concept that I'm talking about.

At the same time, I would like to attach right after the title of the section the page number in which I have found the information because it helps me to find it in the bibliography later on. But in doing so, as you would expect, the text appears below the title's section.

Do you know any way to change the \section command to let me introduce some text without breaking the line?

I have seen some questions related to my post but they use shortcuts to avoid redefining the \section command (like using lists). I think that the titlesec package would help me, but I don't know how to use it. In this respect, it would be really helpful if you could help me to understand how to use it properly.

Thank you!

Edit(2): Here is MWE:

\documentclass{article}

\usepackage{titlesec}

\begin{document}

\section*{Name of the section} (page)

\paragraph*{Name of the section} (page)

\titleformat*{\paragraph}{\Large \bfseries}

\paragraph*{Name of the section} (page)

\end{document}

Edit: Regarding @Zarko comment, I would like to use the section command and do what it can be done with the paragraph one. My question it would be how to modify the section command to act as if it was a paragraph with respect to the line breaking of the line after the head of the section.

lockstep
  • 250,273
  • 1
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Jun 21 '15 at 05:48
  • Instead of section you can use \paragraph{...}. – Zarko Jun 21 '15 at 07:25
  • is there a reason you can't include {\mdseries\protect\cite{...}} right in the section title? – barbara beeton Jun 21 '15 at 12:34
  • @Christian Firstly, I'm not a non-native English speaker so thank you editing my typos. As I'm new in this site I don't know how to add a MWE. But I would appreciate your help in this respect. – Eduard Garriga Viudes Jun 21 '15 at 20:13
  • @barbarabeeton What do you mean by including {\mdseries\protect\cite{...}}? It is for citing the bibliography? – Eduard Garriga Viudes Jun 21 '15 at 20:26
  • Would you like your sections to look the same way that the paragraph command looks, i.e., the section title on the same line as the text? Or do you just want some specific extra information to appear after the section title (like your page number) and then the actual section starts on a new line? The first is easy to do; the second would be better done with a separate command. – Alan Munn Jun 21 '15 at 20:29
  • @AlanMunn I would prefer the second one. But could you explain me how to do the first one as well? I want to learn a little bit more about Latex than just how to do it in a practical manner. Thank you! – Eduard Garriga Viudes Jun 21 '15 at 20:53
  • i meant that that information should just be put into the argument of \section{section title {\mdseries\protect\cite(bibref}}} -- that should set the citation info in lightface right on the same line as the section title. – barbara beeton Jun 21 '15 at 21:24
  • @barbarabeeton It looks like it this command it could work, but in my document after the section's head it appers "[?]". Do I need any package to use the instruction? – Eduard Garriga Viudes Jun 21 '15 at 21:49
  • Please consider posting a Minimum Working Example. It will be much easier to help if, for example, we know how you are managing references and bibliography, which class you are using etc. Right now, people are just guessing and that is not very helpful. – cfr Jun 22 '15 at 03:39
  • any time a \cite is issued, unless bibtex (or your bibliography processor of choice) is run, followed by two more runs of latex, the cited work will be identified as ??. first, the bibliography has to be included in the document (the first post-bibtex run of latex), then latex has to run again to pick up the citation references, since the bibliography is (usually) at the end of the document, and the assigned label isn't known until after the first post-bibtex run. latex is "one way" -- something earlier can't be filled in by something later in the same run. – barbara beeton Jun 22 '15 at 12:22
  • @barbarabeeton I think I've got what you meant but I think it is not the same thing as I asked for. I have posted a MWE to show what I want. Am I right? Sorry if I wasn't clear, it is my first post and I'm still a newbie in this site. – Eduard Garriga Viudes Jun 22 '15 at 22:30

2 Answers2

4

Do you just want something like this? I'm still not entirely clear what the command should do about the page but maybe you don't want it to do anything?

\documentclass{article}

\usepackage{titlesec}
\titleformat{\section}[runin]{\Large\bfseries}{\thesection}{0pt}{}[]
\setcounter{secnumdepth}{0}
\begin{document}

\section{Name of the section} (page)

\paragraph{Name of the section} (page)

\titleformat*{\paragraph}{\Large \bfseries}

\paragraph{Name of the section} (page)

\end{document}

sections & paragraphs

cfr
  • 198,882
  • 1
    this is exactly what I was looking for. Thank you very much! As it was my first post, in the beginning I didn't thought that the MWE it will be that helpful to understand what I was asking for. – Eduard Garriga Viudes Jun 24 '15 at 02:41
  • @EduardGarrigaViudes It makes a big difference. It is so easy to think that because you understand what you mean, it will be clear to everyone else. (I say 'you' but I mean 'me', of course. I constantly forget this in all kinds of contexts - not just on TeX.SE :(.) – cfr Jun 24 '15 at 02:48
2

Here's a very simple solution: create your own command that puts the page number into the section heading.

\newcommand{\mysection}[2]{%
    \section*{#1 (p.~#2)}%
}

Use it like this:

\mysection{35}{Macros}
musarithmia
  • 12,463
  • Why not just use \paragraph in this case? I thought the question was precisely how not to have to use something other than \section. But I am not, to be honest, at all clear what the question is still. So this may be the perfect answer to it. – cfr Jun 24 '15 at 00:05
  • @Andrew your answer is quite simple and I really liked it. Sorry everyone else if I wansn't quite clear about what I was asking for. – Eduard Garriga Viudes Jun 24 '15 at 02:37