summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-tabcellalign.html
blob: 928e19b1a20db7bf19516743c456388fd1ef122b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<head>
<title>UK TeX FAQ -- question label tabcellalign</title>
</head><body>
<h3>How to alter the alignment of tabular cells</h3>
<p/>One often needs to alter the alignment of a tabular <code>p</code> (&lsquo;paragraph&rsquo;)
cell, but problems at the end of a table row are common.  With a
<code>p</code> cell that looks like:
<blockquote>
<pre>
... & \centering blah ... \\
</pre>
</blockquote><p>
one is liable to encounter errors that complain about a &ldquo;misplaced
<code>\</code><code>noalign</code>&rdquo; or &ldquo;<a href="FAQ-altabcr.html">extra alignment tab</a>&rdquo;, or the like.
The problem is that the command <code>\\</code> means different things in
different circumstances: the <code>tabular</code> environment
switches the meaning to a value for use in the table, and
<code>\</code><code>centering</code>, <code>\</code><code>raggedright</code> and <code>\</code><code>raggedleft</code> all change the
meaning to something incompatible.  Note that the problem only
arises in the last cell of a row: since each cell is set into a box,
its settings are lost at the <code>&amp;</code> (or <code>\\</code>) that
terminates it. 
<p/><p/>The technique using <code>\</code><code>PBS</code> was developed in the days of LaTeX 2.09
because the actual value of <code>\\</code> that the <code>tabular</code>
environment uses was only available as an internal command.  Nowadays,
the value is a public command, and you can in principle use it
explicitly:
<blockquote>
<pre>
... & \centering blah ... \tabularnewline
</pre>
</blockquote><p>
<p/>The <i>array</i> package provides a command <code>\</code><code>arraybackslash</code>
which restores <code>\\</code> to its correct (within table) meaning;
the command may be used in <i>array</i>&rsquo;s &ldquo;field format&rdquo; preamble
specifications:
<blockquote>

<pre>
\begin{tabular}{... &gt;{\centering\arraybackslash}p{50mm}}
...
</pre>
</blockquote><p>
<p/>The <code>\</code><code>tabularnewline</code> and <code>\</code><code>arraybackslash</code> commands are
(somewhat) modern additions to LaTeX and the <i>array</i>
package, respectively.  If neither is available, the user may try the
(old) solution which preserves the meaning of <code>\\</code>:
<blockquote>
<pre>
\newcommand\PBS[1]{\let\temp=\\%
  #1%
  \let\\=\temp
}
</pre>
</blockquote><p>
which one uses within a table as:
<blockquote>
<pre>
... & \PBS\centering blah ... \\
</pre>
</blockquote><p>
or in the preamble as:
<blockquote>
<pre>
\begin{tabular}{...&gt;{\PBS\centering}p{5cm}}
</pre>
</blockquote><p>
<dl>
<dt><tt><i>array.sty</i></tt><dd>Distributed as part of <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/macros/latex/required/tools.zip">macros/latex/required/tools</a> (or <a href="http://www.tex.ac.uk/www.tex.ac.uk  tex-archive/macros/latex/required/tools/">browse the directory</a>)
</dl>

<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=tabcellalign">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=tabcellalign</a>
</body>