1

I use LaTeX, but I only consider myself an average user. I have a special need. If I have a \section{Something} and I would like { something else } on the same vertical line as the section. But aligned right. How would I go about doing that?

Deleted
  • 5,108

3 Answers3

3

If you only want to do this once... don't. Find some other way to present that single bit of information. \hfil[l][l] will work, but it can play havoc with the Table of Contents if you're not careful, and in general you just shouldn't go there.

If you want to add a little bit of extra information to every section title, or even most of them, you're going to have to hack the sectioning commands. You'll probably end up declaring some kind of \customsection[Optional ToC text]{Section title}{Extra information you want on the right side} command. If you can, use the titlesec package; it will save you a lot of time.

kquinn
  • 780
  • Interesting, I didn't know about \hfil and \hfilll. When are they used? – jtbandes Jul 24 '09 at 23:34
  • Usually, when you're making quick and dirty hacks :) They're part of the original TeX and are described in detail in Knuth's TeXBook, but all three are basically the same. The more ls the command has, the more powerful it is: two \hfil on a line will expand to the same size (useful for centering), but throw in one \hfill and it will overpower the \hfils and dominate all the space itself. \hfilll is the nuclear bomb of TeX glue commands, and will crush everything in its path... use it with caution. – kquinn Jul 24 '09 at 23:40
  • It seems SuperUser botched the formatting on that comment... I'm pretty sure I got it correct, and there's just a bug in the SU code. I'll see if it gets fixed soon, and if not file a bug report on MSO.... – kquinn Jul 24 '09 at 23:41
  • I guess my question is, what's the point of overpowering the other things like \hfil if they'll completely disappear? You could just not include them. – jtbandes Jul 24 '09 at 23:42
  • If you're writing in pure TeX and you control everything, there's not much point to them. If you're doing complicated stuff with both standard and custom macros, you'll learn to love them. – kquinn Jul 24 '09 at 23:46
  • Thank you!

    By the way! I've been thinking about buying Knuth's TeXBook. I'd like to dwelve deeper into the world of TeX and LaTeX, but when it comes to something like this issue, I'm a quite lost. At the moment I'm mostly using what's available in the The Not So Short Introduction to LaTeX2e. Do you think Knuth's book is the book I should buy?

    – Deleted Jul 25 '09 at 10:57
  • Honestly, it's not that useful unless you're going to be writing a lot of plain TeX macros. LaTeX is rather different, and the TeXBook was written before LaTeX even existed. The LaTeX Companion second edition has been far more useful to me; the TeXBook is more an occasional reference than anything else. You can probably just grab it from a library should you need it. – kquinn Jul 25 '09 at 21:07
3

Aha, I found something that may be useful! The titlesec package has a bunch of customizations for titles, including section titles.

Here is a PDF of examples which contains something like this, #8.

jtbandes
  • 8,870
  • Yes it looks really useful and I didn't know about it! :-) For my simple needs this time I'll go with the \hfill solution (I'm just writing a resume), but I'm sure it will come in handy in the future. – Deleted Jul 25 '09 at 10:59
2

Use \hfill .

\section{Something \hfill something else}

Note, that answer your requirement for appearance, I'm not too sure whether you only want "Something" considered as part of the title, because the above solution consider "Something something else" as the title.

KTC
  • 383
  • I was going to post that, but I figured the idea was not to have it be part of the title. Plus, that would probably break the table of contents and other things. – jtbandes Jul 24 '09 at 23:21
  • You can still define another text to appear in the table of contents, though. Dunno about how hyperref treats this. But that thing breaks pretty easily on nearly everything that is unusual, so I don't expect much anymore. – Joey Jul 24 '09 at 23:33
  • Thank you! I went with the \hfill solution. I won't be using a TOC in this document (my resume), if I need to I'll probably use the titlesec package. I'm choosing the other answer as my accepted one, as both posts where posted 11 hours ago and the other one is a bit more detailed and has one more vote. It's at times like this I would like the option to pick two accepted answers. Thank you! (And of course I up-vote) – Deleted Jul 25 '09 at 11:01