2012-09-25 151 views
2

我有下面的代碼有問題:文本對齊

\begin{table}[!h] 
    \centering 
    \caption{Titel} 
    \resizebox{.95\columnwidth}{!}{% 
    \begin{tabular}{p{4.5cm}p{10cm}p{3.5cm}} 
     \hline 
     Name & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}} 
      {long_title which goes over two coloums}\\ 
     \hline 
     Explanation & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}} 
      {Explanation which goes over two coloums}\\ 
     \hline 
     \multirow{3}{*}{Targets} 
      & Target 1 is long text with two lines & not reached\\ 
     \cline{2-3} 
     & Target 2 & reached\\ 
     \cline{2-3} 
     & Target 3 & reached\\ 
     \hline 

    \end{tabular}% 
    } 
    \label{tab:test}% 
\end{table}% 

我希望這張照片有助於理解我的問題:

Problem Example

我想對齊單元格頂部的文本「目標」,如第二個表格。我相信這一定很容易做到,但我似乎無法指責它。請幫助我進行這種對齊。

+0

我必須使用別的不是「*」嗎? –

+0

這看起來像你的問題的反面,它可能會幫助你:http://stackoverflow.com/questions/1910478/centering-text-within-a-multirow-cell-in-latex –

+0

抱歉,但我不知道如何adpat,我嘗試使用vfill和居中都不工作 –

回答

1

而不是明確指定列的寬度使用l說明符(這可能需要數組包)。其使用的一個例子是以下

\begin{center} 
    \begin{tabular}{ | l | l | l | p{5cm} |} 
    \hline 
    Day & Min Temp & Max Temp & Summary \\ \hline 
    Monday & 11C & 22C & A clear day with lots of sunshine. 
    However, the strong breeze will bring down the temperatures. \\ \hline 
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells 
    across most of Scotland and Northern Ireland, 
    but rain reaching the far northwest. \\ \hline 
    Wednesday & 10C & 21C & Rain will still linger for the morning. 
    Conditions will improve by early afternoon and continue 
    throughout the evening. \\ 
    \hline 
    \end{tabular} 
\end{center} 

這將提供一個輸出這樣

Example

注意所有列的頂部對齊。

我希望這會有所幫助。

+0

謝謝你的嘗試,但有一個原因,爲什麼我有寬度 –