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.

this problem is driving me nuts. I need a line of text formatted as follows:

Avian Influenza       Tamiflu          Jan 2, 2011
* This is a random description, note that it spans 
  mult. cols.
* These bullet points--would like to use itemize
  for them.

Chicken pox           DrugXYZ          Feb 3, 1998
* This is another description.
* The "headers" (e.g. DrugXYZ, Avian Influenza) can  
be different, and have different lengths.

basically, I want Avian Influenza to be left-aligned, Tamiflu to be centered, and Jan 2, 2011 to be right-aligned, such that the disease, dates and drug names in both sets are aligned at the same tabs. Altogether, the three should span the textwidth.

I tried to use tabular, but I want to be able to use itemize, etc in the "stuff" portion.

Any ideas??

share|improve this question
    
Hi Asker, welcome to TeX.stackexchange. I've formatted your samples as code, which you can do by selecting the text and pressing the {} button. –  Jake Jun 18 '11 at 7:57
2  
May I suggest you add a complete minimal working example that shows the kind of text you want to align? As it is, the question could be interpreted in a number of different ways. –  Jake Jun 18 '11 at 8:13
    
@Jake: Indeed - it seems that I saw this rather differently to the intention of the questioner. –  Joseph Wright Jun 18 '11 at 8:14
add comment

4 Answers

up vote 4 down vote accepted

Another possible solution:

\documentclass{article}
\usepackage{array}

\newcommand\MyHeadings[3]{%
  \multicolumn{2}{@{}p{0.45\textwidth}@{}}{#1}  & #2 & #3 \tabularnewline
}
\newcommand\Description[1]{%
  \textbullet & \multicolumn{3}{@{}p{0.97\textwidth}@{}}{#1}\tabularnewline}

\begin{document}

\noindent
\begin{tabular}{@{}p{0.03\textwidth}@{}p{0.42\textwidth}@{}p{0.3\textwidth}@{}>{\raggedleft}p{0.25\textwidth}@{}}
\MyHeadings{Avian Influenza}{Tamiflu}{Jan 2, 2011}
\Description{stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff}
\Description{stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff}
\MyHeadings{Chicken pox}{DrugXYZ}{Feb 3, 1998}
\Description{stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff}
\Description{stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff}
\end{tabular}

\end{document}

And yet another option: tabular is only used for the words requiring alignment, the descriptions are left to an itemize environment (customized with the help of enumitem):

\documentclass{article}
\usepackage{enumitem}
\usepackage{array}

\setitemize{leftmargin=*,nolistsep}
\newcommand\MyHeadings[3]{%
  \noindent\begin{tabular}  {@{}p{0.45\textwidth}@{}p{0.3\textwidth}@{}>{\raggedleft}p{0.25\textwidth}@{}}
    #1 & #2 & #3
\end{tabular}\par
}

\begin{document}

\MyHeadings{Avian Influenza}{Tamiflu}{Jan 2, 2011}
\begin{itemize}
  \item stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
  \item stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
\end{itemize}
\MyHeadings{Chicken pox}{DrugXYZ}{Feb 3, 1998}
\begin{itemize}
  \item stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
  \item stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
\end{itemize}


\end{document}
share|improve this answer
    
brilliant..I ended up using the second solution –  Asker Jun 18 '11 at 18:39
add comment

A simple application of \hfil should suffice. For example, wrapping things up in a macro what is wrong with

\documentclass{article}
\newcommand\threethings[3]{%
  \noindent #1\hfil #2\hfil #3\\\ignorespaces
}
\begin{document}

\threethings{SomeWords1}{SomeWords2}{SomeWords3}
stuff stuff stuff stuff stuff stuf
stuff stuff stuff stuff

\threethings{SomeWords1}{SomeWords2}{SomeWords3}
stuff stuff stuff stuff stuff stuf
stuff stuff stuff stuff
\end{document}

Based on the comment, a second possible approach

\documentclass{article}
\newcommand*\mylength{0.33343\textwidth}
\newcommand\threethings[3]{%
  \noindent
  \begin{tabular}{@{}p{\mylength}@{}p{\mylength}@{}p{\mylength}@{}}
   \raggedright #1 & \centering #2 & \raggedleft #3
  \end{tabular}
}
\begin{document}

\threethings{SomeWords1}{SomeWords2}{SomeWords3}
stuff stuff stuff stuff stuff stuff
stuff stuff stuff stuff

\threethings{SomeWords1}{SomeWords2}{SomeWords3}
stuff stuff stuff stuff stuff stuff
stuff stuff stuff stuff

\threethings{Short1}{Short2}{Short3}
stuff stuff stuff stuff stuff stuf
stuff stuff stuff stuff
\end{document}
share|improve this answer
    
thanks for the note Joseph; I tried something like this, however, the different instances are not properly aligned. Somewords1 and Somewords3 are properly aligned, but Somewords2 in the two instances are not at the same tab stop....it seems like Somewords2 is actually in the middle of Somewords1 and Somewords3 in that particular line...whereas I need it to be in the middle of the page –  Asker Jun 18 '11 at 8:09
add comment

The alignment you require can be obtained by saying

\usepackage{enumitem}
\newenvironment{disease}[3]
  {\par\addvspace{\topsep}\noindent
   \makebox[0pt][l]{#1}\makebox[\textwidth]{#2}\makebox[0pt][r]{#3}
   \par\nobreak
   \begin{itemize}[topsep=0pt,beginpenalty=10000]}
  {\end{itemize}\addvspace{\topsep}}

\begin{document}

\begin{disease}{Avian Influenza}{Tamiflu}{Jan 2, 2011}
\item stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff

\item stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff stuff
\end{disease}

There will be no break between the heading and the first line of the itemized list.

share|improve this answer
add comment
\documentclass{report}
\usepackage{tabularx}
\begin{document}

\noindent
\begin{tabularx}{\linewidth}{@{}p{0.333\linewidth}@{} >{\centering}X @{}
                  >{\raggedleft}p{0.333\linewidth}@{}}
SomeWords1  & SomeWords2  & SomeWords3\tabularnewline
stuff stuff & stuff stuff & stuff stuf\tabularnewline
stuff stuff & stuff stuff 
\end{tabularx}

\end{document}

enter image description here

share|improve this answer
    
interesting...can I use itemize inside tabularx?...the way I meant to write it, I need the "stuff" part to span all columns, i.e. a single row spanning 3 columns –  Asker Jun 18 '11 at 8:16
    
sure: but I do not really understand how do you want to use it. Make a complete example, maybe you can extend my one ... –  Herbert Jun 18 '11 at 8:22
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.