LaTeX forum ⇒ Fonts & Character SetsText direction of Arabic in table Topic is solved

Information and discussion about fonts and character sets (e.g. how to use language specific characters)
Ahmed Sokar
Posts: 4
Joined: Wed Jul 27, 2016 9:43 am

Text direction of Arabic in table

Postby Ahmed Sokar » Wed Jul 27, 2016 9:56 am

Hello,

I want to write arabic in table
  1. \documentclass[14pt]{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage[LAE]{fontenc}
  4. \usepackage[german,arabic]{babel}
  5.  
  6.  
  7. \begin{document}
  8. محمد - أحمد
  9.  
  10. \begin{tabular}[]{|c|c|}\hline
  11. محمد & أحمد
  12. \\\hline
  13. \end{tabular}
  14.  
  15. \end{document}

The result is

Untitled.png
Untitled.png (3.02 KiB) Viewed 1967 times


So how can i force the text direction from right to left in the table?
Last edited by Ahmed Sokar on Wed Jul 27, 2016 10:50 am, edited 1 time in total.

User avatar
Johannes_B
Site Moderator
Posts: 3584
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Wed Jul 27, 2016 10:29 am

The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

User avatar
Stefan Kottwitz
Site Admin
Posts: 8536
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Fri Jul 29, 2016 6:26 pm

Hi Ahmed,

welcome to the forum!

If anything doesn't work, save it in a box. :-) That's good for TikZ nodes, but also for tabular content or content that shows issues within another environment.

Declare a box:

  1. \newsavebox{\mybox}


Use it, in this case we chose the array package to define a new column type, here C for right to left centered:

  1. \usepackage{array}
  2. \newcolumntype{C}{>{\begin{lrbox}{\mybox}}c<{\end{lrbox}\AR{\unhbox\mybox}}}


Then you can use C in your table instead:

  1. \begin{tabular}[]{|C|C|
  2. ...


Complete example:

  1. \documentclass[14pt]{article}
  2. \usepackage[utf8]{inputenc}
  3. \usepackage[LAE]{fontenc}
  4. \usepackage[german,arabic]{babel}
  5.  
  6. \newsavebox{\mybox}
  7. \usepackage{array}
  8. \newcolumntype{C}{>{\begin{lrbox}{\mybox}}c<{\end{lrbox}\AR{\unhbox\mybox}}}
  9. \begin{document}
  10. محمد - أحمد
  11.  
  12. \begin{tabular}[]{|C|C|}\hline
  13. محمد & أحمد
  14. \\\hline
  15. \end{tabular}
  16.  
  17. \end{document}


That's similar to what Salim Bou suggested.

Stefan
Site admin

Ahmed Sokar
Posts: 4
Joined: Wed Jul 27, 2016 9:43 am

Postby Ahmed Sokar » Tue Aug 02, 2016 2:40 am

That worked

thank you!


Return to “Fonts & Character Sets”

Who is online

Users browsing this forum: No registered users and 3 guests