2

I've tried making a table like this, but I failed letting the text in the first column be centered. Here is my code, can anyone give me a hint?

\documentclass[11pt,a4paper,oneside]{book}
\usepackage{amsmath,amsxtra,amssymb,latexsym, amscd,amsthm}
\usepackage{longtable}
\usepackage{multirow}
\usepackage[left=1.5cm,right=1.5cm,top=1.5cm,bottom=1.5cm]{geometry}
\usepackage{arydshln}

\begin{document}
\thispagestyle{empty}

\begin{longtable}{||c|c|p{0.75cm}||}
\hline\hline
\multirow{4}{*}{\parbox{.08\textwidth}{\centering 1 \\ (1 diem)}} & \parbox{.8\textwidth}{dong 1a \\ dong 1b\\ dong 1c} & \parbox{.07\textwidth}{0.25} \\ \cdashline{2-3}
& \parbox{.8\textwidth}{dong 2a \\ dong 2b\\ dong 2c}  & \parbox{.07\textwidth}{0.25} \\ \cdashline{2-3}
& \parbox{.8\textwidth}{dong 3a \\ dong 3b\\ dong 3c \\ dong n} & \parbox{.07\textwidth}{0.25} \\ \cdashline{2-3}
& \parbox{.8\textwidth}{dong 4a \\ dong 4b\\ dong 4c \\ dong n \\ dong n+1} & \parbox{.07\textwidth}{0.25}\\ \hline\hline
\end{longtable}
\end{document} 
3
  • Welcome. \multirow{4} play around with the number. Try 12.
    – Johannes_B
    May 7 '16 at 7:17
  • Thanks Johannes. Is there any other options because my text in the second column is very long so I can't count how many line it has. May 7 '16 at 7:24
  • Maybe use an m-column. I really cannot even think about something elegant, because there are so many distracting lines and the table setup is also quite confusing. Instead of using all thos parboxes, try p-columns.
    – Johannes_B
    May 7 '16 at 8:15
2

On majority of your problems your receive advises in comments of @Johannes_B. Considering them you can write your table as:

\documentclass[11pt,a4paper,oneside]{book}
%\usepackage{amsmath,amsxtra,amssymb,latexsym, amscd,amsthm}
\usepackage{array,longtable,multirow}
\usepackage[left=1.5cm,right=1.5cm,top=1.5cm,bottom=1.5cm]{geometry}
\usepackage{arydshln}

\begin{document}
\thispagestyle{empty}

\begin{longtable}{||c|m{.8\textwidth}|>{\centering\arraybackslash}m{0.75cm}||}
    \hline\hline
\multirow{14}{.08\textwidth}{\centering 1 \\ (1 diem)}
    &   dong 1a \newline dong 1b\newline dong 1c
        &   0.25                                        \\  \cdashline{2-3}
    &   dong 2a \newline dong 2b\newline dong 2c  
        &   0.25                                        \\  \cdashline{2-3}
    &   dong 3a \newline dong 3b\newline dong 3c \newline dong n 
        &   0.25                                        \\  \cdashline{2-3}
    &   dong 4a \newline dong 4b\newline 
        dong 4c \newline dong n \newline dong n+1
        &   0.25                                        \\ 
    \hline\hline
\end{longtable}
\end{document} 
\begin{longtable}{||c|m{.8\textwidth}|>{\centering\arraybackslash}m{0.75cm}||}
    \hline\hline
\multirow{14}{.08\textwidth}{\centering 1 \\ (1 diem)}
    &   dong 1a \newline dong 1b\newline dong 1c
        &   0.25                                        \\  \cdashline{2-3}
    &   dong 2a \newline dong 2b\newline dong 2c  
        &   0.25                                        \\  \cdashline{2-3}
    &   dong 3a \newline dong 3b\newline dong 3c \newline dong n 
        &   0.25                                        \\  \cdashline{2-3}
    &   dong 4a \newline dong 4b\newline 
        dong 4c \newline dong n \newline dong n+1
        &   0.25                                        \\ 
    \hline\hline
\end{longtable}
\end{document} 

which gives:

enter image description here

In above code I use column type m{...} from array package, which simplify settings in the last column.

Let me pointed that there is no more elegant way of use multirow package than counting number of lines, which multi row cell should span. In placing of cell content the multirow is not very accurate, actually it provide optional parameter for moving its content up or down:

\multirow{nrows}[bigstruts]{width}[fixup]{text}

where bigstruts is mainly used if you've used bigstrut.sty and fixup is a length used for fine tuning of vertical position of cell's content.

Since you use longtable probably you will like to broke table over more pages. There can arise problems, how to broke multi row cell. I'm afraid that this is not possible to be done automatically. So you will be forced to manually divided on more cell, or find different way to design of your table.

Addendum: In case of real use of long table, I suggest to reformat your table in something like this:

enter image description here

Here is no problem with multirow cells` and the first row will allways appear on the top of the table ...

\documentclass[11pt,a4paper,oneside]{book}
%\usepackage{amsmath,amsxtra,amssymb,latexsym, amscd,amsthm}
\usepackage{array,longtable,multirow}
\usepackage[left=1.5cm,right=1.5cm,top=1.5cm,bottom=1.5cm]{geometry}
\usepackage{arydshln}

\usepackage{caption}% <-- new

\begin{document}
\thispagestyle{empty}

\begin{longtable}{||m{.8\textwidth}
                   |>{\centering\arraybackslash}m{0.75cm}||}
\caption{For final form of table it have to be complied at list twice (usually three times).}
    \label{table1}                                                      \\
    \hline\hline
\multicolumn{2}{||c||}{1 (1 diem)}      \\
    \hline
\endfirsthead
\captionsetup{textformat =continued}
    \hline
\multicolumn{2}{||c||}{1 (1 diem)}      \\
    \hline
\endhead
    \hline
\multicolumn{2}{r}{continued on the next page}
\endfoot
    \hline\hline
\endlastfoot
% table content
dong 1a \newline dong 1b\newline dong 1c
        &   0.25                                        \\  \hdashline
dong 2a \newline dong 2b\newline dong 2c  
        &   0.25                                        \\  \hdashline
dong 3a \newline dong 3b\newline dong 3c \newline dong n 
        &   0.25                                        \\  \hdashline
dong 4a \newline dong 4b\newline 
                 dong 4c \newline dong n \newline dong n+1
        &   0.25                                        \\ 
\end{longtable}
\end{document} 
1
  • Yes @Zarko , I'd like to break my table over more pages. As your answer, the only way is counting the lines. And your suggestion with the new format is useful. However, I still want to keep the old one. I will try to break it with 'newpage', it seems not so "beatiful" but that works. Haha. Thank you May 8 '16 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.