1

I want my all cells have horizontally and vertically centered except second column. I want my second column only vertically centered, but the alignment is on the left.

My attempt:

\documentclass[a4paper]{book} \usepackage{blindtext} \usepackage{amssymb} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amsthm} \begin{document} \begin{center} \begin{tabular}{|c|c|p{4cm}|} \hline No. & $f(t)$ & $F(s)$\\ \hline 1. & Fungsi tangga konstan, $f(t)=1$ & $$\frac 1s;\, s>0$$\\ \hline 2. & Fungsi identitas, $f(t)=t$ & $$\frac 1{s^2};\, s>0$$\\ \hline 3. & Fungsi eksponensial, $f(t)=1$ & $$\frac 1s;\, s>0$$\\ \hline 4. & Fungsi tangga konstan, $f(t)=e^{-\omega t}$ & $$\frac 1{s+\omega};\, s>0$$\\ \hline \end{tabular} \end{center} \end{document} 

Can you help me? I've seen my possible duplicate, but seems like there is an error when I'm using \usepackage{ragged2e}. And I want the width to fit the text length naturally. For example, the first column has a smaller width.

3
  • 1
    \begin{tabular}{|c|l|m{4cm}|} should result in the desired alignment. Commented Aug 6, 2020 at 10:37
  • @leandriis it's error. Commented Aug 6, 2020 at 10:45
  • 1
    Did you load the array package? The m column type is only available when the array package is loaded. Commented Aug 6, 2020 at 11:06

2 Answers 2

2

To vertically centre cells contents, you can use the cellspace package, which ensures a minimal vertical spacing at the top and bottom of cells in columns with specifier prefixed with the letter S (unfortunately already used by siunitx), or any letter you want with the loading option column=:

\documentclass[a4paper]{book} \usepackage{blindtext} \usepackage{array} \usepackage[column=O]{cellspace} \setlength{\cellspacetoplimit}{5pt} \setlength{\cellspacebottomlimit}{4pt} \usepackage{amssymb} \usepackage{amsmath} \usepackage{amsthm} \begin{document} \begin{center} \begin{tabular}{|c|l|>{$\displaystyle}Oc<{$}|} \hline No. & \multicolumn{1}{c|}{$f(t)$} & F(s)\\ \hline 1. & Fungsi tangga konstan, $f(t)=1$ & \frac 1s;\, s>0 \\ \hline 2. & Fungsi identitas, $f(t)=t$ & \frac 1{s²};\, s>0 \\ \hline 3. & Fungsi eksponensial, $f(t)=1$ & \frac 1s;\, s>0 \\ \hline 4. & Fungsi tangga konstan, $f(t)=e^{-ωt}$ & \frac 1{s+ω};\, s>0 \\ \hline \end{tabular} \end{center} \end{document} 

enter image description here

5
  • Thank you very much for the answer, i really appreciate it. Commented Aug 6, 2020 at 11:08
  • Hi, can i have a last question please? My last problem is the header of the table. I want them all to centered but won't affect the other cells. (the second column of the header still on the left) Commented Aug 6, 2020 at 11:58
  • 2
    Use \multicolumn{1}{|c|}{$f(t)$} for the head of the 2nd column. Commented Aug 6, 2020 at 12:01
  • @Bernard: I think that there is a slight mistake in your comment. It should be \multicolumn{1}{c|}{$f(t)$}. Commented Aug 6, 2020 at 15:31
  • @F.Pantigny: You're right. One of my many lapsus calami Commented Aug 6, 2020 at 15:51
1

Centering both for horz and vert -- I think you will make out the difference and be able to do the rest-- if not please revert

enter image description here

\begin{tabular}{ | >{\centering\arraybackslash}m{1in}% instead of "p" is "m" | >{\centering\arraybackslash}m{1in}% instead of "p" is "m" | >{\centering\arraybackslash}m{1in}% instead of "p" is "m" |} \hline No. & $f(t)$ & $F(s)$\\ \hline 1. & Fungsi tangga konstan, $f(t)=1$ & $$\frac 1s;\, s>0$$\\ \hline 2. & Fungsi identitas, $f(t)=t$ & $$\frac 1{s^2};\, s>0$$\\ \hline 3. & Fungsi eksponensial, $f(t)=1$ & $$\frac 1s;\, s>0$$\\ \hline 4. & Fungsi tangga konstan, $f(t)=e^{-\omega t}$ & $$\frac 1{s+\omega};\, s>0$$\\ \hline \end{tabular} 
1
  • Thank you very much for the answer, i really appreciate it. Commented Aug 6, 2020 at 11:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.