如何使表格中的水平文本居中

如何使表格中的水平文本居中
\documentclass{article}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{array}
\usepackage{rotating}
\usepackage{makecell} 

\begin{document}

\begin{table}

\small

\caption{Studies on Highway }

\begin{tabular}{|p{3.4cm}|p{4cm}|p{7.8cm}|}

\hline

Optimization &  Methods &  References \\ \hline

\multirow{3}{*}{\begin{sideways} {Horizontal} \end{sideways}} 

                       & Calculus &  Howard  \\  \cline{2-3}
                       & Network  & Turner \\  \cline{2-3}
                       & Dynamic  &  Nicholson  \\ \cline{2-3}

\hline
\multirow{3}{*}{\begin{sideways} {Vertical alignment only} \end{sideways}} 

                  & Enumeration & Easa  \\  \cline{2-3}
                  & Dynamic & Puy \\  \cline{2-3}
                  & Linear  & Canale  \\  \cline{2-3}
                  & Numerical & Robinson \\   \cline{2-3} 
                  & Swarm intelligence & Kazemi \\ \hline


\end{table}

\end{document}

答案1

我会避免垂直设置文本,因为这会使阅读变得困难。

\documentclass[a4paper,12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,tabularx,array,caption}

\begin{document}
\begin{table}

\caption{Studies on Highway Alignment Optimization divided by Optimization Element}
\label{tab:Studies on highway}

\footnotesize
\begin{tabularx}{\textwidth}{
  >{\raggedright\hsize=.5\hsize}X
  >{\raggedright\arraybackslash\hsize=1.5\hsize}X
}
\toprule
\multicolumn{1}{c}{\bfseries Methods} & \multicolumn{1}{c}{\bfseries References} \\ 
\midrule
\multicolumn{2}{l}{\bfseries Horizontal alignment only} \\
\addlinespace

Calculus of variation &
  Howard et al. (1968), Shaw \& Howard (1981 \& 1982), 
  Thomson and Sykes (1988), \& Wan (1995) \\
\addlinespace

Network optimization &
  Turner \& Miles (1971), OECD (1973), Athanassoulis and Calogero (1973),
  Parker (1977), and Trietsch (1987a \& 1987b) \\
\addlinespace

Dynamic programming &
  Hogan (1973) and Nicholson et al.\ (1976) \\
\addlinespace

Genetic algorithms &
  Jong (1998) and Jong et al.\ (2000)\\
\addlinespace

Neighbourhood search-heuristic with MIP &
 Yusin Lee and Liang Liu (2009)\\
\addlinespace

Swarm intelligence &
  Jha (2004), Yousef (2013)\\ 

\midrule

\multicolumn{2}{l}{\bfseries Vertical alignment only} \\
\addlinespace

Enumeration &
  Easa (1988) \\
\addlinespace

Dynamic programming &
  Puy Harte (1973), Murchland (1973),  Fwa (1989),
  Goktepe \& Altun (2005) \\
\addlinespace

Linear programming &
  Chapra and Canale (1988) \& ReVelle et al.(1997),
  Weixing Li \& Songshan (2005), Goktepe \& Altun (2009),
  Warren \& Valentin (2011) \\
\addlinespace

Numerical search &
  Hayman (1970) and Robinson (1973) \\ 
\addlinespace

Swarm intelligence &
  Kazemi \& Shafahi (2013)\\  
\midrule

\multicolumn{2}{l}{\bfseries Three-dimensional (3D) alignment} \\
\addlinespace

Numerical search &
  Chew et al.\ (1989) \\
\addlinespace

Network optimization &
  De Smith (2006) \\
\addlinespace

Neighbourhood search-heuristic with MIP &
  Cheng and Lee (2006) \\
\addlinespace

Numerical search &
  Hayman (1970) and Robinson (1973) \\ 
\addlinespace

Genetic algorithms &
  Jong (1998), Jha (2000), Kim (2001), Jong \& Schonfeld (2003),
  Chan \& Fan (2003), Jha \& Schonfeld (2004), Jha et al.\ (2006),
  Kang \& Schonfeld (2009),Jha \& Maji (2009), Jha \& Maji (2011),
  Jha, Jong \& Schonfeld (2012), \&  Jha (2013) \\
\addlinespace

Swarm intelligence &
  Yang, W. A. (2010), Yousef (2013) \\
\bottomrule

\end{tabularx}

\end{table}

\end{document}

\&请检查您的输入:和之间的选择and似乎不一致。还et al.\应该使用 来代替et. al

在此处输入图片描述

答案2

为了进行水平对齐,您可以使用>{\centering}表格格式描述。如果要对这些单元格进行垂直对齐,可以使用制造细胞包。下面是一个例子:

\documentclass[a4paper,12pt]{article}

%\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{multirow}
\usepackage{makecell}

\begin{document}
\begin{table}
\small
\caption{Studies on Highway Alignment Optimization}
\setlength{\extrarowheight}{2pt}
\begin{tabular}{|>{\centering}m{3.4cm}|m{4cm}|m{7.8cm}|}
\hline
\begin{center}
 Optimization Element
\end{center}
 & 
 \begin{center}
 Methods
 \end{center}
  & 
  \begin{center}
   References
  \end{center}
 \\ 
\hline
\multirow{6}{*}{\begin{sideways} {Horizontal alignment only} \end{sideways}}   & Calculus of variation &  Howard et al. (1968), Shaw \& Howard (1981 \& 1982), Thomson and Sykes (1988), \& Wan (1995) \\
 \cline{2-3}

& Network optimization & Turner \& Miles (1971), OECD (1973), Athanassoulis and Calogero (1973), Parker (1977), and Trietsch (1987a \& 1987b) \\   \cline{2-3}

& Dynamic programming & Hogan (1973) and Nicholson et. al (1976) \\ \cline{2-3}

& Genetic algorithms & Jong (1998) and Jong et. al (2000)\\ \cline{2-3} 

& Neighbourhood search-heuristic with MIP & Yusin Lee and Liang Liu (2009)\\  \cline{2-3}

& Swarm intelligence & Jha (2004), Yousef (2013)\\ 
\hline
\multirow{5}{*}{\begin{sideways} {Vertical alignment only} \end{sideways}}   & Enumeration & Easa (1988) \\ \cline{2-3}
                  & Dynamic programming & Puy Harte (1973), Murchland (1973),  Fwa (1989), Goktepe \& Altun (2005) \\ \cline{2-3}
                  & Linear programming & Chapra and Canale (1988) \& ReVelle et al.(1997), Weixing Li \& Songshan (2005), Goktepe \& Altun (2009), Warren \& Valentin (2011) \\  \cline{2-3}
                  & Numerical search & Hayman (1970) and Robinson (1973)\\  \cline{2-3} 
                  & Swarm intelligence & Kazemi \& Shafahi (2013)\\  
\hline

\multirow{6}{*}{\begin{sideways}{Three-dimensional (3D) alignment} \end{sideways}}   & Numerical search & Chew et al. (1989) \\\cline{2-3}
                  & Network optimization & De Smith (2006) \\  \cline{2-3}
                  & Neighbourhood search-heuristic with MIP & Cheng and Lee (2006) \\  \cline{2-3}
                  & Numerical search & Hayman (1970) and Robinson (1973)\\  \cline{2-3} 
                  & Genetic algorithms & Jong (1998), Jha (2000), Kim (2001), Jong \& Schonfeld (2003), Chan \& Fan (2003), Jha \& Schonfeld (2004), \& Jha et al.(2006),Kang \& Schonfeld (2009),Jha \& Maji (2009), Jha \& Maji (2011), Jha, Jong \& Schonfeld (2012),  Jha (2013)\\  \cline{2-3}
                  & Swarm intelligence & Yang, W.A (2010), Yousef (2013)\\ 
\hline

\end{tabular}
\label{tab:Studies on highway}
\setlength{\extrarowheight}{0pt}
\end{table}
\end{document}

相关内容