I used below code to create a table. The problem is, I want the first coloumn from right to be left aligned and first coloumn from left to be right aligned. Also I want the first row of all column to be right aligned. Could anyone help me?
Asked
Active
Viewed 8,089 times
1 Answers
5
It seems that left is right and right is left in the columns specifier of the tabular environment. Starting the table with
\begin{tabular}{l|l|r}
makes the rightmost column and the center column left-aligned and the leftmost column right-aligned. To change the alignment of single entries, enclose the headers that should be right-aligned in
\multicolumn{1}{r|}{...}
\documentclass{article}
%\documentclass[a4paper,11pt,openany,oneside,phd]{report}
\usepackage{amsthm,amssymb,amsmath}
\usepackage{graphicx} % inserting images
%\usepackage{hyperref} % PDF links
\usepackage{mathrsfs}
\usepackage{amsbsy}
\usepackage{setspace} % for switching between double/single space in document
\usepackage{fancyhdr} % package for changing Headings style
% setting the margins of page
\usepackage[top=2.5cm,right=2.5cm,bottom=2cm,left=2cm]{geometry}
\usepackage{xepersian}
\newcommand{\ba}{\begin{align}}
\newcommand{\ea}{\end{align}}
\newcommand{\nn}{\nonumber}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\bea}{\begin{eqnarray}}
\newcommand{\eea}{\end{eqnarray}}
\renewcommand{\baselinestretch}{1.3}
\def\nn{\nonumber}
\defpersianfont\nastaliq[Scale=1.6]{IranNastaliq.ttf}
\defpersianfont\nastaliqq[Scale=2]{IranNastaliq.ttf}
\pagestyle{fancy}
\cfoot{}
\lhead{\thepage}
\settextfont[Scale=1.2]{XBZar.ttf}
\setdigitfont[Scale=1.1]{XBZar.ttf}
\begin{document}
\begin{table}[htp]
\centering
\caption{بیبعدqسازی} \label{tab:my}
\begin{tabular}{l|l|r}
\multicolumn{1}{r|}{کمیت }&\multicolumn{1}{r|}{ مقدار بیبعدنشده }& مقدار بیبعد شده \\
شعاع ویچک& $r = 2 \mu m$ & $\bar{r}= \frac{r}{l} =1$ \\
سرعت ذاتی باکتری& $v_0 = 2 \frac{\mu m}{s}$ & $\bar{v}_0 = \frac{v_0 l^2}{l D_\parallel} = 40$ \\
گام زمانی شبیه سازی& $\Delta t = 1 s$ & $\overline{\Delta t}= \frac{D_\parallel \Delta t}{l^2} =0.1$ \\
ضریب پخش زاویهای شناگر& $D_r = \frac{3 k_{B}T \: ln(\frac{l}{b})}{\pi \: \eta \: l^3} = 0.3 \frac{1}{s}$& $\bar{D}_r = \frac{D_r \times l^2}{D} =14$ \\
ضریب پخش انتقالی شناگر& $D_\parallel = 0.1 \frac{\mu m^2}{s}$ & $\bar{D_\parallel}= \frac{D_\parallel}{D_\parallel} =1$ \\
ضریب پخش غذا& $D_c = \frac{k_B T}{6 \pi \eta r_0} = 20 \frac{\mu m^2}{s}$ & $\bar{D}_c= \frac{D_c}{D} =2000$ \\
ضریب کموتکسی زاویهای& $\chi_r = ?$ & $\bar{\chi}_r=?$ \\
ضریب کموتکسی انتقالی& $\chi_{tr} = ?$ & $\bar{\chi}_{tr}= ?$ \\
چگالی شناگرها& $\rho_0 = ?$ & $\bar{\rho}_0= l^2 \times \rho_0 =?$ \\
فاصلهی سایتهای شبکه& $\Delta l = ?$ & $\overline{\Delta l}= \frac{\Delta l}{l} =?$ \\
چگالی اولیهی غذا& $c_0 = ?$ & $\bar{c}_0 = c_0 \times l^2 = ?$ \\
نرخ مصرف غذا& $K=?$ & $\bar{K}= \frac{K l^2}{D_\parallel}=?$ \\
\end{tabular}
\end{table}
\end{document}
Edit: From the comments it seems that all columns should be left-aligned and all headings right-aligned. Second try:
...
\caption{بیبعدqسازی} \label{tab:my}
\begin{tabular}{l|l|l}
\multicolumn{1}{r|}{کمیت}
& \multicolumn{1}{r|}{ مقدار بیبعدنشده }
& \multicolumn{1}{r}{ مقدار بیبعد شده }
\\
شعاع ویچک
& $r = 2 \mu m$
& $\bar{r}= \frac{r}{l} =1$
\\
...
Edit 2: To color rows, load the packages xcolor and colortbl, define the color for the first row using \definecolor or \colorlet, and then set the color in the table using the command \rowcolor. Side note: Consider to increase \arraystretch to make the table better readable, see below.
\documentclass{article}
\usepackage{xcolor,colortbl}
\colorlet{headline}{blue!30} % define headline color in one place such that it can be changed easily for the whole document
\usepackage{xepersian}
\defpersianfont\nastaliq[Scale=1.6]{IranNastaliq.ttf}
\defpersianfont\nastaliqq[Scale=2]{IranNastaliq.ttf}
\settextfont[Scale=1.2]{XBZar.ttf}
\setdigitfont[Scale=1.1]{XBZar.ttf}
\begin{document}
\begin{table}[htp]
\centering
\caption{بیبعدqسازی} \label{tab:my}
{\renewcommand\arraystretch{1.5}%
\begin{tabular}{l|l|l}
\rowcolor{headline}
\multicolumn{1}{r|}{کمیت}
& \multicolumn{1}{r|}{ مقدار بیبعدنشده }
& \multicolumn{1}{r}{ مقدار بیبعد شده }
\\
شعاع ویچک
& $r = 2 \mu m$
& $\bar{r}= \frac{r}{l} =1$
\\
سرعت ذاتی باکتری
& $v_0 = 2 \frac{\mu m}{s}$
& $\bar{v}_0 = \frac{v_0 l^2}{l D_\parallel} = 40$
\end{tabular}%
}
\end{table}
\end{document}
gernot
- 49,614
-
-
@saranj Well, you wrote: "I want ... and first coloumn from left to be right aligned". So the first column from left is right aligned. – gernot Apr 02 '17 at 16:32
-
-
Sorry. You are correct. It was a mistake by me. BTW, Is there any way to make the first row of table coloured? – sara nj Apr 02 '17 at 16:52
-
-
@gernot ahahhah. I have written the truth. Thank you for writing in Arabic :-) – Sebastiano Apr 02 '17 at 19:32
-



mathrsfstwice? – Mico Apr 02 '17 at 10:23\begin{tabular}{r|c|l}and\multicolumn{1}{c}{<column header>}at first and last column header (from left :) ) ? – Zarko Apr 02 '17 at 11:02\begin{tabular}{r|c|l}\hline\multicolumn{1}{c}{<1. column header>} & <2. column header> & \multicolumn{1}{c}{<3.column header>} \\ right aligned text & centered text & left aligned text \\ .... I understand, that you like to have something like this (all is considered from left to right). – Zarko Apr 02 '17 at 16:45