Graphics, Figures & Tables ⇒ newcolumntype with mathmode
newcolumntype with mathmode
I want to create some tables with tabularx, which contain much formula stuff. This specific table has 1 column for formula description and 2 colums for the formulas. I dont want to type the math-environment "$ $" for each single field, so i tried to create a new columtype which is automatically in mathmode.
I found \newcolumntype{Z}{>{$}X<{$}} via Google, which is supposed to do exactly what I want.
When I now use the environment
\begin{tabularx}{350pt}{X|Z|X|X}
\end{tabularx}
compiling with pdflatex (using texmaker) i get errors. The created table has some spacing errors, but the math-environment seems to work, because the log doesnt show any $-errors (autofill, replace, bla)
Is the \newcolumntype definition wrong? I did programming stuff before and know principles of arguments etc., but the huge load of possibilities and selfclaimed tutorials is too much.
If you need more information like the sourcecode let me know,so I will post it.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
newcolumntype with mathmode
Yes, indeed. It is always helpful to prepare a minimal example. In this case it is indispensable. Your descriptions are too vague to comprehend the problem.breien36 wrote:[…] If you need more information like the source code let me know, so I will post it.
Best regards and welcome to the board
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
newcolumntype with mathmode
Code: Select all
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\newcolumntype{Z}{>{$}X<{$}}
\begin{tabularx}{350pt}{X|Z|X|X}
A & 2+2=4 & C & D \\
E & 2+3=5 & H & I
\end{tabularx}
\end{document}
newcolumntype with mathmode
sorry i didnt post a MWE the first time. Here it is:
Code: Select all
\documentclass[11pt,a4paper]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[ngerman]{babel}
\usepackage{tabularx}
\newcolumntype{Z}{>{$}X<{$}}
\begin{document}
\begin{tabularx}{350pt}{r|Z|Z|Z}
Größen & elektrisches Strömungsfeld & elektrisches Feld in Nichtleitern & magnetisches Feld \\
\hline
Feldvektoren & \overrightarrow{E}, \overrightarrow{S} & \overrightarrow{E}, \overrightarrow{D} & \overrightarrow{H}, \overrightarrow{B} \\
\hline
Zsh. Feldvektoren & \overrightarrow{S} = \gamma \overrightarrow{E} & \overrightarrow{D} = \epsilon \overrightarrow{E} & \overrightarrow{H} = \mu \overrightarrow{B} \\
\hline
\hline
Integrale Größen \\
\hline
Ströme und Flüsse & I = \int \overrightarrow{S} d \overrightarrow{A} & \Psi = \int \overrightarrow{D} d \overrightarrow{A} & \Phi = \int \overrightarrow{B} d \overrightarrow{A} \\
\hline
\end{tabularx}
\end{document}
Code: Select all
This is pdfTeX, Version 3.1415926-1.40.11 (Web2C 2010) (format=pdflatex 2010.12.28) 21 JAN 2011 12:55
entering extended mode
restricted \write18 enabled.
%&-line parsing enabled.
**temp.tex
(./temp.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2009-06-19, ngerman-x-2009-06-19, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, farsi, finnish, french,
galician, german, ngerman, swissgerman, monogreek, greek, hungarian, icelandic
, assamese, bengali, gujarati, hindi, kannada, malayalam, marathi, oriya, panja
bi, tamil, telugu, indonesian, interlingua, irish, italian, kurmanji, lao, lati
n, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, polish, portu
guese, romanian, russian, sanskrit, serbian, slovak, slovenian, spanish, swedis
h, turkish, turkmen, ukrainian, uppersorbian, welsh, loaded.
(c:/texlive/2010/texmf-dist/tex/latex/koma-script/scrartcl.cls
Document Class: scrartcl 2010/09/17 v3.07 KOMA-Script document class (article)
(c:/texlive/2010/texmf-dist/tex/latex/koma-script/scrkbase.sty
Package: scrkbase 2010/09/17 v3.07 KOMA-Script package (KOMA-Script-dependent b
asics and keyval usage)
(c:/texlive/2010/texmf-dist/tex/latex/koma-script/scrbase.sty
Package: scrbase 2010/09/17 v3.07 KOMA-Script package (KOMA-Script-independent
basics and keyval usage)
(c:/texlive/2010/texmf-dist/tex/latex/graphics/keyval.sty
Package: keyval 1999/03/16 v1.13 key=value parser (DPC)
\KV@toks@=\toks14
)
(c:/texlive/2010/texmf-dist/tex/latex/koma-script/scrlfile.sty
Package: scrlfile 2009/03/25 v3.03 KOMA-Script package (loading files)
Package scrlfile, 2009/03/25 v3.03 KOMA-Script package (loading files)
Copyright (C) Markus Kohm
))) (c:/texlive/2010/texmf-dist/tex/latex/koma-script/tocbasic.sty
Package: tocbasic 2010/09/14 v3.06a KOMA-Script package (handling toc-files)
)
Package tocbasic Info: omitting babel extension for `toc'
(tocbasic) because of feature `nobabel' available
(tocbasic) for `toc' on input line 115.
Package tocbasic Info: omitting babel extension for `lof'
(tocbasic) because of feature `nobabel' available
(tocbasic) for `lof' on input line 116.
Package tocbasic Info: omitting babel extension for `lot'
(tocbasic) because of feature `nobabel' available
(tocbasic) for `lot' on input line 117.
Package scrartcl Info: You've used obsolete option `11pt'.
(scrartcl) \KOMAExecuteOptions{fontsize=11pt} will be
(scrartcl) used instead.
(scrartcl) You may simply replace `11pt'
(scrartcl) by `fontsize=11pt'.
Class scrartcl Info: File `scrsize11pt.clo' used to setup font sizes on input l
ine 1210.
(c:/texlive/2010/texmf-dist/tex/latex/koma-script/scrsize11pt.clo
File: scrsize11pt.clo 2010/09/17 v3.07 KOMA-Script font size class option (11pt
)
)
(c:/texlive/2010/texmf-dist/tex/latex/koma-script/typearea.sty
Package: typearea 2010/09/17 v3.07 KOMA-Script package (type area)
Package typearea, 2010/09/17 v3.07 KOMA-Script package (type area)
Copyright (C) Frank Neukam, 1992-1994
Copyright (C) Markus Kohm, 1994-
\ta@bcor=\skip41
\ta@div=\count79
Package typearea Info: You've used standard option `a4paper'.
(typearea) This is correct!
(typearea) Internally I'm using `paper=a4'.
(typearea) If you'd like to set the option with \KOMAoptions,
(typearea) you'd have to use `paper=a4' there
(typearea) instead of `a4paper', too.
\ta@hblk=\skip42
\ta@vblk=\skip43
\ta@temp=\skip44
Package typearea Info: These are the values describing the layout:
(typearea) DIV = 10
(typearea) BCOR = 0.0pt
(typearea) \paperwidth = 597.50793pt
(typearea) \textwidth = 418.25555pt
(typearea) DIV departure = -6%
(typearea) \evensidemargin = 17.3562pt
(typearea) \oddsidemargin = 17.3562pt
(typearea) \paperheight = 845.04694pt
(typearea) \textheight = 595.80026pt
(typearea) \topmargin = -25.16531pt
(typearea) \headheight = 17.0pt
(typearea) \headsep = 20.40001pt
(typearea) \topskip = 11.0pt
(typearea) \footskip = 47.60002pt
(typearea) \baselineskip = 13.6pt
(typearea) on input line 1134.
)
\c@part=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\abovecaptionskip=\skip45
\belowcaptionskip=\skip46
\c@pti@nb@sid@b@x=\box26
\c@figure=\count86
\c@table=\count87
\bibindent=\dimen102
) (c:/texlive/2010/texmf-dist/tex/latex/base/inputenc.sty
Package: inputenc 2008/03/30 v1.1d Input encoding file
\inpenc@prehook=\toks15
\inpenc@posthook=\toks16
(c:/texlive/2010/texmf-dist/tex/latex/ucs/utf8x.def
File: utf8x.def 2004/10/17 UCS: Input encoding UTF-8
))
(c:/texlive/2010/texmf-dist/tex/latex/ucs/ucs.sty
Package: ucs 2004/10/17 UCS: Unicode input support
(c:/texlive/2010/texmf-dist/tex/latex/ucs/data/uni-global.def
File: uni-global.def 2004/10/17 UCS: Unicode global data
)
\uc@secondtry=\count88
\uc@combtoks=\toks17
\uc@combtoksb=\toks18
\uc@temptokena=\toks19
)
(c:/texlive/2010/texmf-dist/tex/latex/amsmath/amsmath.sty
Package: amsmath 2000/07/18 v2.13 AMS math features
\@mathmargin=\skip47
For additional information on amsmath, use the `?' option.
(c:/texlive/2010/texmf-dist/tex/latex/amsmath/amstext.sty
Package: amstext 2000/06/29 v2.01
(c:/texlive/2010/texmf-dist/tex/latex/amsmath/amsgen.sty
File: amsgen.sty 1999/11/30 v2.0
\@emptytoks=\toks20
\ex@=\dimen103
))
(c:/texlive/2010/texmf-dist/tex/latex/amsmath/amsbsy.sty
Package: amsbsy 1999/11/29 v1.2d
\pmbraise@=\dimen104
)
(c:/texlive/2010/texmf-dist/tex/latex/amsmath/amsopn.sty
Package: amsopn 1999/12/14 v2.01 operator names
)
\inf@bad=\count89
LaTeX Info: Redefining \frac on input line 211.
\uproot@=\count90
\leftroot@=\count91
LaTeX Info: Redefining \overline on input line 307.
\classnum@=\count92
\DOTSCASE@=\count93
LaTeX Info: Redefining \ldots on input line 379.
LaTeX Info: Redefining \dots on input line 382.
LaTeX Info: Redefining \cdots on input line 467.
\Mathstrutbox@=\box27
\strutbox@=\box28
\big@size=\dimen105
LaTeX Font Info: Redeclaring font encoding OML on input line 567.
LaTeX Font Info: Redeclaring font encoding OMS on input line 568.
\macc@depth=\count94
\c@MaxMatrixCols=\count95
\dotsspace@=\muskip10
\c@parentequation=\count96
\dspbrk@lvl=\count97
\tag@help=\toks21
\row@=\count98
\column@=\count99
\maxfields@=\count100
\andhelp@=\toks22
\eqnshift@=\dimen106
\alignsep@=\dimen107
\tagshift@=\dimen108
\tagwidth@=\dimen109
\totwidth@=\dimen110
\lineht@=\dimen111
\@envbody=\toks23
\multlinegap=\skip48
\multlinetaggap=\skip49
\mathdisplay@stack=\toks24
LaTeX Info: Redefining \[ on input line 2666.
LaTeX Info: Redefining \] on input line 2667.
)
(c:/texlive/2010/texmf-dist/tex/latex/amsfonts/amsfonts.sty
Package: amsfonts 2009/06/22 v3.00 Basic AMSFonts support
\symAMSa=\mathgroup4
\symAMSb=\mathgroup5
LaTeX Font Info: Overwriting math alphabet `\mathfrak' in version `bold'
(Font) U/euf/m/n --> U/euf/b/n on input line 96.
)
(c:/texlive/2010/texmf-dist/tex/latex/amsfonts/amssymb.sty
Package: amssymb 2009/06/22 v3.00
)
(c:/texlive/2010/texmf-dist/tex/generic/babel/babel.sty
Package: babel 2008/07/06 v3.8l The Babel package
(c:/texlive/2010/texmf-dist/tex/generic/babel/ngermanb.ldf
Language: ngermanb 2008/07/06 v2.6n new German support from the babel system
(c:/texlive/2010/texmf-dist/tex/generic/babel/babel.def
File: babel.def 2008/07/06 v3.8l Babel common definitions
\babel@savecnt=\count101
\U@D=\dimen112
)
\l@naustrian = a dialect from \language\l@ngerman
Package babel Info: Making " an active character on input line 92.
))
(c:/texlive/2010/texmf-dist/tex/latex/tools/tabularx.sty
Package: tabularx 1999/01/07 v2.07 `tabularx' package (DPC)
(c:/texlive/2010/texmf-dist/tex/latex/tools/array.sty
Package: array 2008/09/09 v2.4c Tabular extension package (FMi)
\col@sep=\dimen113
\extrarowheight=\dimen114
\NC@list=\toks25
\extratabsurround=\skip50
\backup@length=\skip51
)
\TX@col@width=\dimen115
\TX@old@table=\dimen116
\TX@old@col=\dimen117
\TX@target=\dimen118
\TX@delta=\dimen119
\TX@cols=\count102
\TX@ftn=\toks26
) (./temp.aux)
\openout1 = `temp.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 12.
LaTeX Font Info: ... okay on input line 12.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 12.
LaTeX Font Info: ... okay on input line 12.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 12.
LaTeX Font Info: ... okay on input line 12.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 12.
LaTeX Font Info: ... okay on input line 12.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 12.
LaTeX Font Info: ... okay on input line 12.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 12.
LaTeX Font Info: ... okay on input line 12.
(c:/texlive/2010/texmf-dist/tex/latex/ucs/ucsencs.def
File: ucsencs.def 2003/11/29 Fixes to fontencodings LGR, T3
)
(c:/texlive/2010/texmf-dist/tex/latex/amsfonts/umsa.fd)
(c:/texlive/2010/texmf-dist/tex/latex/amsfonts/umsb.fd)
(c:/texlive/2010/texmf-dist/tex/latex/ucs/data/uni-0.def)
! Please use \mathaccent for accents in math mode.
<recently read> \accent
l.28 \end{tabularx}
I'm changing \accent to \mathaccent here; wish me luck.
(Accents are not the same in formulas as they are in text.)
! Missing { inserted.
<to be read again>
\fontdimen
l.28 \end{tabularx}
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)
! Missing } inserted.
<inserted text>
}
l.28 \end{tabularx}
I've put in what seems to be necessary to fix
the current column of the current alignment.
Try to go on, since this might almost work.
! Please use \mathaccent for accents in math mode.
<recently read> \accent
l.28 \end{tabularx}
I'm changing \accent to \mathaccent here; wish me luck.
(Accents are not the same in formulas as they are in text.)
! Missing { inserted.
<to be read again>
\fontdimen
l.28 \end{tabularx}
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)
! Missing } inserted.
<inserted text>
}
l.28 \end{tabularx}
I've put in what seems to be necessary to fix
the current column of the current alignment.
Try to go on, since this might almost work.
LaTeX Warning: Command \" invalid in math mode on input line 28.
! Please use \mathaccent for accents in math mode.
<recently read> \accent
l.28 \end{tabularx}
I'm changing \accent to \mathaccent here; wish me luck.
(Accents are not the same in formulas as they are in text.)
! Missing { inserted.
<to be read again>
\fontdimen
l.28 \end{tabularx}
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)
! Missing } inserted.
<inserted text>
}
l.28 \end{tabularx}
I've put in what seems to be necessary to fix
the current column of the current alignment.
Try to go on, since this might almost work.
Overfull \hbox (64.5255pt too wide) in paragraph at lines 28--28
[]|$\OML/cmm/m/it/10.95 elektrischesStr[]$|
[]
Overfull \hbox (83.82715pt too wide) in paragraph at lines 28--28
[]|$\OML/cmm/m/it/10.95 elektrischesFeldinNichtleitern$|
[]
Overfull \hbox (19.21219pt too wide) in paragraph at lines 28--28
[]|$\OML/cmm/m/it/10.95 magnetischesFeld$|
[]
[1
{c:/texlive/2010/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./temp.aux) )
Here is how much of TeX's memory you used:
3287 strings out of 493738
43785 string characters out of 3146582
137630 words of memory out of 3000000
6567 multiletter control sequences out of 15000+200000
8288 words of font info for 32 fonts, out of 3000000 for 9000
714 hyphenation exceptions out of 8191
37i,22n,43p,320b,595s stack positions out of 5000i,500n,10000p,200000b,50000s
<
c:/texlive/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmex10.pfb><c:/texliv
e/2010/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb><c:/texlive/2010/te
xmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb><c:/texlive/2010/texmf-dist/f
onts/type1/public/amsfonts/cm/cmsy10.pfb>
Output written on temp.pdf (1 page, 44620 bytes).
PDF statistics:
24 PDF objects out of 1000 (max. 8388607)
16 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)
newcolumntype with mathmode
Is this what you're after?
Code: Select all
\documentclass[11pt,a4paper]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[ngerman]{babel}
\usepackage{tabularx}
\newcolumntype{Z}{>{$}X<{$}}
\begin{document}
\begin{tabularx}{350pt}{r|Z|Z|Z}
Größen &\multicolumn{1}{X|}{elektrisches Strömungsfeld} & \multicolumn{1}{X|}{elektrisches Feld in Nichtleitern} & \multicolumn{1}{X}{magnetisches Feld} \\
\hline
Feldvektoren & \overrightarrow{E}, \overrightarrow{S} & \overrightarrow{E}, \overrightarrow{D} & \overrightarrow{H}, \overrightarrow{B} \\
\hline
Zsh. Feldvektoren & \overrightarrow{S} = \gamma \overrightarrow{E} & \overrightarrow{D} = \epsilon \overrightarrow{E} & \overrightarrow{H} = \mu \overrightarrow{B} \\
\hline
\hline
Integrale Größen \\
\hline
Ströme und Flüsse & I = \int \overrightarrow{S} d \overrightarrow{A} & \Psi = \int \overrightarrow{D} d \overrightarrow{A} & \Phi = \int \overrightarrow{B} d \overrightarrow{A} \\
\hline
\end{tabularx}
\end{document}
Re: newcolumntype with mathmode

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
newcolumntype with mathmode
Then please mark the topic (not the last post) accordingly.breien36 wrote:Well, thats exactly how I want it. […]
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10