7

How to make this kind of tabbed paragraph: 3 columns 2cm 10cm 2cm, the last column is right aligned and it's content starts on the last line of the paragraph of the second column.

10.      Some text or description here 
         can has more than one line           300

This is what I have so far:

\documentclass[10pt,a4paper]{report}
\begin{document}
\begin{tabular}{p{2cm}p{10cm}p{2cm}}
10. &
Some text or description here can has more than one line &
\raggedleft{300} \\
\end{tabular}
\end{document}

I dont know how to vertically align last column

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
spajak
  • 173

2 Answers2

6

It's probably easiest to make the final part part of the main paragraph so it naturally aligns with the last row. Exactly how to do that depends a bit on whether it needs to be multiple line or not, but for example

enter image description here

\documentclass[10pt,a4paper]{report}
\setlength\textwidth{16cm}
\begin{document}
\begin{tabular}{p{2cm}p{10cm}p{2cm}}
10. &
Some text or description here can has more than one line 
Some text or description here can has more than one line 
\hfill 300\hspace{-2cm}\mbox{}\\
\end{tabular}
\end{document}
David Carlisle
  • 757,742
  • It works. But what is mbox{} for? – spajak Aug 19 '13 at 12:07
  • @spajak latex tabular code trims white space from the start and end of the cell so the negative hspace would get removed by an \unskip if it was right at the end of the cell. – David Carlisle Aug 19 '13 at 12:09
  • You probably want to accommodate for the \tabcolsep as well. – Werner Aug 19 '13 at 13:04
  • 1
    @Werner perhaps or perhaps you just want \hspace{-any length big enough to stop latex complaining about overful box} the exact amount doesn't make any difference in most cases. – David Carlisle Aug 19 '13 at 13:05
4

this looks very much like a toc entry.

i find that it's easier to think of this as a centered (block) paragraph, with the first element sticking out to the left, and the last element sticking out to the right. i also find it's easier to code this as a delimited macro, plain-style. here is a definition that has withstood the test of time.

\documentclass[12pt]{report}
\newdimen{\mylistindent}
\setlength\mylistindent{2cm}
\def\listline #1\\#2\\#3\par{%
  \begingroup
    \rightskip\mylistindent
    \noindent\hangindent\mylistindent
    \hbox to\mylistindent{\ignorespaces #1\hfil}%
    \ignorespaces #2\hfill\rlap{\kern\mylistindent\llap{#3\unskip}}%
    \par
  \endgroup
}

\pagestyle{empty}
\begin{document}

\listline 10\\
   Some text or description here can have more than one line.
   Some text or description here can have more than one line.\\
   200
\par

\noindent Here is some more text that is more than one line to
show that the formatted line stretches out to both margins.

\end{document}

output from example code

David Carlisle
  • 757,742