# How to make text left aligned in the center aligned column？

Just like photo， every text is center aligned in columns， but "ADC_CH115" has different length.. so can I make it left aligned with others, and others still center aligned in columns

Another problem is, I have used \\[-0.5em] to add some vspace in Table, but it makes the line broken. How can I fix it?

The MWE for Test:

\documentclass{article}

\usepackage{array}
\usepackage{caption}
\usepackage{tabularx}

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}[h]
\renewcommand\arraystretch{1.3}

\begin{tabularx}{\textwidth}{|Y|Y|Y|Y|}
\noalign{\hrule height 0.75pt}

\textsf{\bfseries Funktion} & \textsf{\bfseries STM32\_Pin} & \textsf{\bfseries Pin\_Name} & \textsf{\bfseries Pin\_Funktion} \\

\noalign{\hrule height 0.5pt}

\noalign{\hrule height 0.75pt}
\end{tabularx}

\end{table}

\end{document}

• the problem with the gap can be solved like this : \\ &&&\[-0.5em] (You had to keep the column seperators even if the columns are empty.). The allign problem is somehow complicated (tex.stackexchange.com/questions/134550/…) without phantom but can be fixed by adding phantom. See my answer – koleygr Oct 21 '17 at 15:38

I suggest you use \rlap to make the "excess" numerals stick out to the right without affecting the other centering operations. This methods "works" if there are only 1 or 2 "excess" numerals, which is (thankfully) the case here.

And, instead of \\ \\[-0.5em], type \\[1ex].

\documentclass{article}
\usepackage{caption}
\usepackage{tabularx} % 'tabularx' loads 'array' automatically
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}[h]
\renewcommand\arraystretch{1.3}
\begin{tabularx}{\textwidth}{|Y|Y|Y|Y|}
\noalign{\hrule height 0.75pt}

\textsf{\bfseries Funktion} &
\textsf{\bfseries STM32\_Pin} &
\textsf{\bfseries Pin\_Name} &
\textsf{\bfseries Pin\_Funktion} \\

\noalign{\hrule height 0.5pt}

\noalign{\hrule height 0.75pt}
\end{tabularx}
\end{table}
\end{document}

• very cool and very easy to use， Thank you very much ^_^ – sun0727 Oct 21 '17 at 16:33

The problem with the gap can be solved like this : \ &&&[-0.5em] (You had to keep the column separators even if the columns are empty.). The general align problem is somehow complicated without phantom or similar but here can be fixed by adding phantom:

\documentclass{article}

\usepackage{array}
\usepackage{caption}
\usepackage{tabularx}

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}[h]
\renewcommand\arraystretch{1.3}

\begin{tabularx}{\textwidth}{|Y|Y|Y|Y|}
\noalign{\hrule height 0.75pt}

\textsf{\bfseries Funktion} & \textsf{\bfseries STM32\_Pin} & \textsf{\bfseries Pin\_Name} & \textsf{\bfseries Pin\_Funktion} \\

\noalign{\hrule height 0.5pt}

$\hphantom{15}$ADC\_CH115 & PB1 & D6 & $\hphantom{2}$ADC1\_IN12 \\

\noalign{\hrule height 0.75pt}
\end{tabularx}

\end{table}

\end{document}


Second way (split the columns):

\documentclass{article}

\usepackage{array}
\usepackage{caption}
\usepackage{tabularx}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\begin{document}

\begin{table}[h]
\renewcommand\arraystretch{1.3}

\begin{tabularx}{\textwidth}{|R@{\_}L|Y|Y|R@{\_}L|}
\noalign{\hrule height 0.75pt}

\multicolumn{2}{|c|}{\textsf{\bfseries Funktion}} & \textsf{\bfseries STM32\_Pin} & \textsf{\bfseries Pin\_Name}
& \multicolumn{2}{c|}{\textsf{\bfseries Pin\_Funktion}} \\

\noalign{\hrule height 0.5pt}


• after adding an $\hphantom{2}$ in Pin_Function column same line fixing the second alignment too – koleygr Oct 21 '17 at 15:43