The problem is that the \begin{...}
and \end{...}
pair commands automatically create a "group" so that, in effect, the &
and \\
are "out of scope" for the tabular, while inside the "production" environment they just show up at a place where the compiler is not expecting them.
A second problem with your definitions is that, even if they would work, they would be adding an extra \\
at the end of the tabular, adding an unwanted space at the end. Perhaps some more appropriate definitions would be
\documentclass[a4paper,10pt]{article}
\newcommand{\production}[1]{#1 ::= &}
\newenvironment{grammar}{\tabular{p{3cm}l}}{\endtabular}
\begin{document}
\begin{grammar}
\production{XmlStartTag} ... \\
\production{XmlOtherTag} ... \\
\production{XmlEndTag} ...
\end{grammar}
\end{document}
Note no \\
at the end of the last production. Also in the definition of the grammar
you don't need to repeat the work of \begin
/\end
, and you can instead directly use \tabular
and \endtabular
.
Probably you looking for something like this:
Edit (after six year!):
For design of table you first need to read some basic literature about LaTeX, for example https://en.wikibooks.org/wiki/LaTeX/Tables (section 2.8).
Most of \multicolumns
in table are clutter. It seems that you for writing of table use some table generator, which are inclined to generation of them even when are not needed. Consequently, as a result, it’s like awful ...
For above showed picture I thoroughly cleaned your code. It is much shorter and clearer now:
\documentclass[twocolumn]{article}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}[htb]\centering
\begin{tabular}{|P{5cm}|c|c|c|c|}
\hline
\multicolumn{1}{|c|}{}& \multicolumn{4}{c|}{\textbf{Concept}}\\ \hline
%------------------------------------------------
\textbf{Critères d'évaluations}& Perfomance& Économie& Légèreté& Simplicité\\ \hline
%------------------------------------------------
Précision des images thermiques [mK]& 50& 100& 65& 65 \\\hline
%------------------------------------------------
Résolution spatiale [mm]& 19& 3.3& 19& 19\\\hline
%------------------------------------------------
Stockage des données [To]& 4& 8& 4& 12\\\hline
%------------------------------------------------
Résolution temporelle des images thermiques [fps]& 60& 64& 50& 50\\\hline
%------------------------------------------------
Signal de sortie de la caméra thermique [bits]& 16& bites me & 14& 14\\\hline
%------------------------------------------------
Interface de communication& 1& 1& 1& 1\\\hline
%------------------------------------------------
Facilité du pilotage& 1& 1& 1& 1\\\hline
%------------------------------------------------
Inspection autonome& 1& 0.75& 1& 1\\\hline
%------------------------------------------------
Vitesse de vol [m/s]& 10& 20& 6& 10\\\hline
%------------------------------------------------
Résistence au vent [km/h]& 36& 64& 97& 39.6\\\hline
%------------------------------------------------
Autonomie de vol [min]& 75& 34& 50& 70\\\hline
%------------------------------------------------
Poids du drone [kg]& 3.25& 2.27& 3.31& 2.915\\\hline
%------------------------------------------------
Détection humaine à l'intérieur du périmètre radial [m] & 33.1& 33.1& 33.1& 33.1\\\hline
%------------------------------------------------
Efficacité des mesures d'urgence& 1& 1& 1& 1\\\hline
%------------------------------------------------
Sécurité constante des données& 1& 1& 1& 1\\\hline
%------------------------------------------------
Respect constant des conditions de vol& 1& 1& 1& 0.5 \\\hline
%------------------------------------------------
Coût total de production [\$]& 70 744& 13 920& 24 128& 67 130\\\hline
\end{tabular}
\end{table}
\end{document}
As you can see, for centering of text in cels with p{...}
column type I defined new column type P
. For this you need to load package array
.
How to designa better lookin tables this on-line presentation. On this sie (TeX:SE) can bi find many examples of beautifully deigned tables.
Maybe in the first step you remove vertical lines and for number aligning use siunitx
package.
Edit: Meanwhile I play with your table to see how to improve looking of your table, Heiko bit me with nice example. Anyway, since my suggestion is slightly different, see, if you can use/learn for future table designs
\documentclass[twocolumn]{article}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{ragged2e}
\usepackage{array,booktabs,makecell}
\renewcommand\theadfont{\bfseries\sffamily}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\begin{document}
\begin{table}[htb]\centering
\renewcommand{\arraystretch}{1.2}
\begin{tabular}{P{5cm}*{4}{S[table-format=3.3]}}%c|c|c|c|
\toprule
& \multicolumn{4}{c}{\thead{Concept}}
\\ \cmidrule{2-5}
\thead{Critères d'évaluations}
& {\thead{Perfomance}}
& {\thead{Économie}}
& {\thead{Légèreté}}
& {\thead{Simplicité}}
\\ \midrule
Précision des images thermiques [mK]
& 50 & 100 & 65 & 65 \\
Résolution spatiale [mm]
& 19 & 3.3 & 19 & 19 \\
Stockage des données [To]
& 4 & 8 & 4 & 12 \\
Résolution temporelle des images thermiques [fps]
& 60 & 64 & 50 & 50 \\
Signal de sortie de la caméra thermique [bits]
& 16 & {bites me} & 14 & 14 \\
Interface de communication
& 1 & 1 & 1 & 1 \\
Facilité du pilotage
& 1 & 1 & 1 & 1 \\
Inspection autonome
& 1 & 0.75 & 1 & 1 \\
Vitesse de vol [m/s]
& 10 & 20 & 6 & 10 \\
Résistence au vent [km/h]
& 36 & 64 & 97 & 39.6 \\
Autonomie de vol [min]
& 75 & 34 & 50 & 70 \\
Poids du drone [kg]
& 3.25 & 2.27 & 3.31 & 2.915 \\
Détection humaine à l'intérieur du périmètre radial [m]
& 33.1 & 33.1 & 33.1 & 33.1 \\
Efficacité des mesures d'urgence
& 1 & 1 & 1 & 1 \\
Sécurité constante des données
& 1 & 1 & 1 & 1 \\
Respect constant des conditions de vol
& 1 & 1 & 1 & 0.5 \\
Coût total de production [\$]
& \num{70 744} & \num{13 920} & \num{24 128} & \num{67 130}
\\ \bottomrule
\end{tabular}
\end{table}
\end{document}
Edit 2: (use of tabularray):
Meanwhile has been developed new, very powerful package tabularray
. Using it at writing of tables is even more consistent. Resulting table is characterized by concise code:
\documentclass{article}
%\usepackage{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\ExplSyntaxOn
\NewChildSelector{eachtwo}
{
\int_step_inline:nnnn {5}{2}{\l_tblr_childs_total_tl}
{ \clist_put_right:Nn \l_tblr_childs_clist {##1} }
}
\ExplSyntaxOff
\begin{document}
\begin{table}[htb]
\centering
% \small
\begin{tblr}{colsep = 4pt,
colspec = {@{} X[l, m, font=\linespread{0.84}\selectfont,
cmd={\hangafter=1\hangindent=1em}]
*{4}{Q[c, si={table-format=3.3}]}
@{}},
row{1,2} = {font=\small\bfseries},
row{3-Z} = {rowsep = 0.5pt},
row{eachtwo} = {abovesep=1.5ex},
}
\toprule
\SetCell[r=2]{c} Critères d'évaluations
& \SetCell[c=4]{c} {{{Concept}}}
& & & \\
\midrule
& {{{Perform.}}}
& {{{Économie}}}
& {{{Légèreté}}}
& {{{Simplicité}}} \\
\midrule
Précision des images thermiques [mK]
& 50 & 100 & 65 & 65 \\
Résolution spatiale [mm]
& 19 & 3.3 & 19 & 19 \\
Stockage des données [To]
& 4 & 8 & 4 & 12 \\
Résolution temporelle des images thermiques [fps]
& 60 & 64 & 50 & 50 \\
Signal de sortie de la caméra thermique [bits]
& 16 & {{{bites me}}}
& 14 & 14 \\
Interface de communication
& 1 & 1 & 1 & 1 \\
Facilité du pilotage
& 1 & 1 & 1 & 1 \\
Inspection autonome
& 1 & 0.75 & 1 & 1 \\
Vitesse de vol [m/s]
& 10 & 20 & 6 & 10 \\
Résistence au vent [km/h]
& 36 & 64 & 97 & 39.6 \\
Autonomie de vol [min]
& 75 & 34 & 50 & 70 \\
Poids du drone [kg]
& 3.25 & 2.27 & 3.31 & 2.915 \\
Détection humaine à l'intérieur du périmètre radial [m]
& 33.1 & 33.1 & 33.1 & 33.1 \\
Efficacité des mesures d'urgence
& 1 & 1 & 1 & 1 \\
Sécurité constante des données
& 1 & 1 & 1 & 1 \\
Respect constant des conditions de vol
& 1 & 1 & 1 & 0.5 \\
Coût total de production [\$]
& {{{\num{70 744}}}}
& {{{\num{13 920}}}}
& {{{\num{24 128}}}}
& {{{\num{67 130}}}}
\\
\bottomrule
\end{tblr}
\end{table}
\end{document}
With the new version of the package (2022B, already available on CTAN) the code will be even shorter and simpler.
(red lines show text area borders)
Best Answer
If you are using any scripting language that passes strings to LaTeX, you should definitely escape them as you probably do not control all data which will be passed and your system should be fail-safe.
This means you should put a
\
before any of&
,#
,{
,}
etc. which would be either causing an error or invisible in the output. If you know about other special symbols like\
you should probably also replace them with\textbackslash
etc. because they could also be a problem.Personally I would avoid using verbatim in an environment where it is absolutely overkill. Processing text should be as easy as possible. And replacing one character by a saved box would just be complicated.
Btw: The mentioned
\texttt
does not do anything like escaping (or switching to verbatim), it just switches to another font.