2

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?

sara nj
  • 203

1 Answers1

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|}{...}

enter image description here

\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_{t‎r} = ?‎$‎ ‎‎‎‎& ‎‎‎$‎\bar{\chi}_{t‎r}= ?‎$ ‎\\‎
‎‏‏چگالی شناگر‌ها& ‎‎$\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:

enter image description here

...
\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.

enter image description here

\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