GeneralRight-aligned citation after quotation, example etc..

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
pandammonium
Posts: 55
Joined: Thu Oct 30, 2008 4:12 pm

Right-aligned citation after quotation, example etc..

Post by pandammonium »

Hello,

I am taking an example from a book and citing the reference with the example. I want the citation right-aligned. If the citation is on the same line as some of the text, \hfill will do the job. If the citation is on a new line (by itself), \hfill apears to be ignored and the citation is on the left.

In the example below, the result is as desired (at least it is when I run it!) but if you remove ", then you'll see the problem" (not forgetting the comma, but leaving the full stop) from the example, the citation is on a line by itself and there is no horizontal filling in sight.

Minimal working example:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[margin=1in]{geometry}
\usepackage{harvard}
\usepackage{gb4e}

\begin{document}

\begin{exe}
   \ex\label{rule:formation:wrong}Add or remove as much text here as required to force the citation onto a new line, then you'll see the problem.\hfill\cite[p.~1]{author:2009}
\end{exe}

\bibliographystyle{apsr}
\bibliography{minworkingex}
\end{document}
Bibliography:

Code: Select all

@BOOK{author:2009,
  AUTHOR =       {Author, A N},
  editor =       {},
  TITLE =        {A really interesting book},
  PUBLISHER =    {A Publisher},
  YEAR =         {2009}
}
I have looked at \hspace, but that requires me to specify a length, which I don't want to do because I may change the margins or font size later on, and I don't want to have to change the values all the time.

I've also looked at various FAQs and formatting guides, but nothing seems to do exactly what I want.

Anyone know how to do it? Any time and effort you spend on this is greatly appreciated. I'm using Kile 2.0.1 on Ubuntu 8.10.

Cheers,

pandammonium
Last edited by pandammonium on Thu Feb 12, 2009 5:13 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

curiouslearn
Posts: 105
Joined: Fri Nov 30, 2007 11:32 pm

Right-aligned citation after quotation, example etc..

Post by curiouslearn »

You can use

Code: Select all

\hspace*{\fill}
pandammonium
Posts: 55
Joined: Thu Oct 30, 2008 4:12 pm

Re: Right-aligned citation after quotation, example etc..

Post by pandammonium »

So I can. Thank you very much, curiouslearn.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Right-aligned citation after quotation, example etc..

Post by localghost »

You could define a new command to align your citations properly.

Code: Select all

\documentclass[english]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\usepackage{lmodern}
\usepackage{blindtext}

\newcommand*{\signed}[1]{%
  \unskip\hspace*{1em plus 1fill}%
  \nolinebreak[3]\hspace*{\fill}\mbox{#1}
}

\begin{document}
  \blindtext
  \signed{$\triangle$}
\end{document}
Of course you can put also a citation as argument for the new command.


Best regards
Thorsten¹
pandammonium
Posts: 55
Joined: Thu Oct 30, 2008 4:12 pm

Right-aligned citation after quotation, example etc..

Post by pandammonium »

Thorsten, thanks for that.

But, when I tried running your example, there were two possible results:
1) a number 1 (one) followed by a space character precede the triangle, or
2) this error is given on compilation (after I dare to change anything to see what puts the '1' there and I still get this error after putting the code back and deleting the output files):
PDFLaTeX wrote:[PDFLaTeX] minworkingex.tex => minworkingex.pdf (pdflatex)
[PDFLaTeX] finished with exit status 1
minworkingex.tex:36:Illegal parameter number in definition of \signed. }
minworkingex.tex:40:You can't use `macro parameter character #' in restricted horizontal mode. \signed
[PDFLaTeX] 2 errors, 0 warnings, 0 badboxes
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Right-aligned citation after quotation, example etc..

Post by localghost »

I'm sorry for that inconvenience. I did a small mistake in the declaration of the new command. Since it has one mandatory argument, the definition needs this number in brackets. This is what I forgot. I corrected that in the code I gave above.
pandammonium
Posts: 55
Joined: Thu Oct 30, 2008 4:12 pm

Re: Right-aligned citation after quotation, example etc..

Post by pandammonium »

Thanks for the fix - that works perfectly now and does exactly what I want.

Note for others: if you want to use this \signed command in a caption, you need to \protect it, otherwise you'll get an error.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Right-aligned citation after quotation, example etc..

Post by localghost »

pandammonium wrote:[...] Note for others: if you want to use this \signed command in a caption, you need to \protect it, otherwise you'll get an error.
Since the citation is not to appear in the ToC, you should use the optional argument for the short form of the caption.

Code: Select all

\caption[Caption for ToC]{Full caption with citation\cite{key}}
The same procedure works for structuring commands (\chapter, \section, ...).
pandammonium
Posts: 55
Joined: Thu Oct 30, 2008 4:12 pm

Re: Right-aligned citation after quotation, example etc..

Post by pandammonium »

Oh, good point! Thanks :)
Post Reply