I'd like to define some tables as commands (MWE) in an external .tex file,
because there are a lot of settings for them. This external file gets included in the main document by the \input{} command. Using my pre-defined commands is no problem. TeXStudio is able to compile the main document and also gives an output. The problem is, that TeXStudio doesn't recognize the \hline command and the & separator for tables inside my self-defined table (the editor says there are table commands outside of table environment). Also, if only the main document is opened in the editor (without the myTemplate file),
the \mytable{} and \lb commands I defined in the external document are not recognized.
Is there a way to make this red highlighting disappear without simply deactivating the syntax-highlighting? I got some help from here: TeXStudio doesn't recognize some commands, because I've had the same Problem with other commands before. Though, These commands were from packages I got from ctan, so no self-defined commands.
I'm not sure if this problem is reproducable for you, but here is a MWE:
\documentclass[]{scrartcl}
\input{myTemplate.tex}
\begin{document}
\mytable{
%% \hline A & B & C & D & E \\ \hline
a & b1 \lb b2 \lb b3 & c1 \lb c2 \lb c3 & d & e \\ \hline
& & & & \\ \hline
& & & & \\ \hline
}
\end{document}
And the myTemplate file:
\usepackage{tabularx}
\usepackage{here}
\usepackage{array}
\usepackage[table]{xcolor}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\newcommand{\mytable}[1]{%
\begin{center}
\rowcolors{1}{white}{pink}
\begin{tabular}{| M{.2\textwidth} | M{.15\textwidth} | M{.1\textwidth} | M{.2\textwidth} | M{.2\textwidth} | M{.15\textwidth}|} \hline
A & B & C & D & E \\ \hline
#1
\end{tabular}
\end{center}%
}
\newcommand{\lb}{\linebreak}

\begin{table}in your definition of\mytable? as you haven't got a caption it would be better and simpler just to usetabular. Also you are missing%after the{and after\end{tabular}– David Carlisle Mar 23 '16 at 07:37rowcolorscommand, which must be put inside a table environment, I think ... But I added this Information and also the%, thanks for the advice! – kanra Mar 23 '16 at 08:20\rowcolorsdoesn't requiretable– David Carlisle Mar 23 '16 at 08:52\rowcolorsoutside a table environment all tables would get these rowcolors, wouldn't they? But I'd like to have this setting only in this particular kind of tables - is this possible without putting it inside thetableenvironment? – kanra Mar 23 '16 at 09:12centerenvironment or just{..}or any other group, it is nothing to do withtable– David Carlisle Mar 23 '16 at 09:22tablewithcenternow, thank you! Just out of curiosity: Why is using another group better than usingtable? – kanra Mar 23 '16 at 09:43