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.

Consider the following code:

\documentclass{article}

\begin{document}

\begin{tabular}{|p{5cm}|}
  \hline
  \textbf{item 1:} These are some texts to just fill in the first line.
   \tabularnewline
   this is the second Item which still needs to be indented
   \begin{itemize}
    \item item 1
\item item 2
   \end{itemize}
 \\ \hline 
\end{tabular}

\end{document}

when you run this you will get a table with one cell. My question is

How can I align the paragraph rows inside tabular except for the first line to start from a specified margin? Said otherwise, how can I have a paragraph indented for every line except for the first (say indented for 1 cm)?

if it matters, my actual code has p{\textwidth}. And BTW I have a itemize in the cell which I'd like to keep.
Please do consider that I am using a right to left language (bidi package is used) and solutions that statically add margin to left are not useful. Actually I need the spacing in the right portion of text not the left.

share|improve this question
    
Perhaps you could show us a (slightly) fuller example, with the itemize? The structure of the table is beginning to sound a bit more complex than we're seeing here... –  Brent.Longborough Dec 28 '10 at 12:46
    
It is updated now. –  Yasser Sobhdel Dec 28 '10 at 12:57
add comment

6 Answers

up vote 6 down vote accepted

Due to technical reasons (or let's say bidirectional typesetting bugs of XeTeX), you need to put list-like environment inside \parbox or minipage environment. Therefore the solution is:

\documentclass{article}
\usepackage{bidi}
\setRTL
\begin{document}

\begin{tabular}{|p{5cm}|}
  \hline
  \textbf{item 1:} These are some texts to just fill in the first line.
   \tabularnewline
   this is the second Item which still needs to be indented
\parbox{5cm}{\leavevmode%
   \begin{itemize}
    \item item 1
\item item 2
   \end{itemize}}
 \\ \hline 
\end{tabular}

\end{document}

or

\documentclass{article}
\usepackage{bidi}
\setRTL
\begin{document}

\begin{tabular}{|p{5cm}|}
  \hline
  \textbf{item 1:} These are some texts to just fill in the first line.
   \tabularnewline
   this is the second Item which still needs to be indented
\begin{minipage}{5cm}
   \begin{itemize}
    \item item 1
\item item 2
   \end{itemize}
\end{minipage}
 \\ \hline 
\end{tabular}

\end{document}
share|improve this answer
add comment

The bug is now fixed and if you have installed version 1.4.2 of bidi package, then my workaround is no longer needed and your original minimal example should work fine.

share|improve this answer
add comment
  • The first row shows only the first line gets pushed to the right.

  • The second row shows all lines except first line get pushed to the right.

alt text

\documentclass{article}

\usepackage[margin=2cm,a4paper]{geometry}

\usepackage{lipsum}

\usepackage{longtable,array,calc}

\newcommand{\dummy}{%
This is my favourite table definition. 
It is very powerful to solve many problems in \LaTeX.
The quick brown dog jumps over the lazy fox.
}

\newcolumntype{A}[1]%
    {%
        >{%
            \begin{minipage}%
            {%
                    #1%
            }%
            \vspace{\tabcolsep}%
         }%
        c%
        <{%
                \vspace{\tabcolsep}%
                \end{minipage}%
         }%
    }%

\newenvironment{First}[1][1cm]
{\hspace{#1}\ignorespaces}
{}

\newenvironment{Complement}[1][1cm]
{\hspace{#1}\begin{minipage}{\linewidth-#1}\hspace{-#1}\ignorespaces}
{\end{minipage}}


\begin{document}

\begin{longtable}{|A{10cm}|}\hline%
 \begin{First}
 \dummy
 \end{First}
 \tabularnewline\hline 
 %============================================
 \begin{Complement}
 \dummy%
 \end{Complement}
 \tabularnewline\hline
\end{longtable}

\end{document}
share|improve this answer
    
(I think) It has incompatibility issues with the bidi package. When writing in right to left it does not show any thing, but when going left to right it is perfect. –  Yasser Sobhdel Dec 28 '10 at 13:10
    
@Yasser, let me know your "MINIMAL" code snippet including all imported packages. I use latex.exe, and you? –  xport Dec 28 '10 at 13:14
    
I am using the same code as yours except for two thing: 1. ‎\usepackage{xepersian}‎ (at the end of \usepackage commands) 2. changing dummy command to something persian (right to left language). When I typeset it, the table shows no text inside. { I am using texLive on Win7) –  Yasser Sobhdel Dec 28 '10 at 13:16
    
i found that using \newtabularline after each paragraph would do the indenting, but for the itemize command, it shifts the itemize to the right. But I want it to be shifted to the left (right to left language). Do you know by chance any command that does so or I have to elaborate a new command for that? –  Yasser Sobhdel Dec 28 '10 at 14:01
add comment

Are you after something like this?:

\documentclass[a5paper]{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|>{\bfseries}lX|}
  \hline
  Item 1:& These are some texts 
  just to fill in the first line. 
  And some more texts 
  just to fill in the second line.\\
  Item 2:& These are some texts 
  just to fill in the first line. 
  And some more texts 
  just to fill in the second line.
 \\ \hline 
\end{tabularx}
\end{document}​

Updated, in the light of more detail in the question:

\documentclass[a5paper]{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|>{\bfseries}lX|}
  \hline
  Item 1:& These are some texts 
  just to fill in the first line. 
  And some more texts 
  just to fill in the second line.\\
  & This is the second Item which still needs to be indented
\begin{itemize}
\item item 1
\item item 2
\end{itemize}
\\ \hline 
\end{tabularx}
\end{document}​

Note that: (a) I've made the major item stub a separate column in the table (Sorry, I don't know whow tabularx works with RTL text); and (b) rather than \tabularnewline, I've added a table row for the second bit. Although this may not match what you're doing syntactically, I think it might make things a bit more maintainable.


This is how I guess RTL might work:

\documentclass[a5paper]{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\textwidth}{|X>{\bfseries}l|}
  \hline
 These are some texts & Item 1: 
  just to fill in the first line. 
  And some more texts 
  just to fill in the second line.\\
  This is the second Item which still needs to be indented
\begin{itemize}
\item item 1
\item item 2
\end{itemize}
\\ \hline 
\end{tabularx}
\end{document}​
share|improve this answer
    
But I have a itemize inside the table which used to work, but now I have trouble with that :(. –  Yasser Sobhdel Dec 28 '10 at 12:18
    
Perhaps you could tell me about how to have the itemize in this please. –  Yasser Sobhdel Dec 28 '10 at 13:32
    
thanks a lot, I think I have to state problem in the forum of the bidi package. –  Yasser Sobhdel Dec 29 '10 at 6:49
add comment
\documentclass{article}
\usepackage{array,paralist}
\begin{document}

\begin{tabular}{|p{5cm}|}  \hline
\begin{compactdesc}
 \item[item 1:] These are some texts to just fill in the first line.
 \item[item 2:] These are some texts to just fill in the first line.
\end{compactdesc}\\\hline
A line after the description environment\\
\hline 
\end{tabular}

\end{document}
share|improve this answer
    
I think you just answer the first scenario where displace ONLY the first line to the right. The second scenario is to push all lines (except the first one) to the right. –  xport Dec 28 '10 at 10:57
    
It does the job, but doesn't resolve the problem. I am using a right to left text (bidirectional) and when applying your solution, they just shift to the right out of the table border. –  Yasser Sobhdel Dec 28 '10 at 11:13
    
@Yasser, please see my solution. I am NOT sure that it is what you need. –  xport Dec 28 '10 at 11:21
    
@xport: please consider the fact that your solution does not work for a right to left language. it simply adds space from the left side not the right side. BTW, I don't know if I can use the itemize with it. –  Yasser Sobhdel Dec 28 '10 at 12:51
add comment

Use the array package and \hangindent. This uses the \everypar primitive to set the hanging indentation for every paragraph. Instead, you can use the everyhook and push and pop the hook before and afterward.

\documentclass{article}
\usepackage{array}
\begin{document}
\begin{tabular}{|>{\everypar{\hangindent1cm}}p{5cm}|}
  \hline
  \textbf{item 1:} These are some texts to just fill in the first line.
 \\ \hline 
\end{tabular}
\end{document}
share|improve this answer
    
it does not solve the problem. After \tabularnewline command it reverts to old style! –  Yasser Sobhdel Dec 28 '10 at 11:25
    
@Yasser: Fixed. –  TH. Dec 28 '10 at 13:58
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.