# write latex code in Lyx for tables

I found this template for a table on TeX.SX:

Beautiful table samples

The table I would like to reproduce is

   \documentclass[12pt, oneside, landscape]{memoir}

\newif\ifblackandwhite
% \blackandwhitetrue

\usepackage{fontspec}%
\defaultfontfeatures{Ligatures=TeX}%
\setmainfont[%
Numbers        = OldStyle ,
ItalicFont     = LinLibertineOI ,
BoldItalicFont = LinLibertineOBI ,
BoldFont       = LinLibertineOB ,
]{LinLibertineO}%

\usepackage[hmargin=2cm,vmargin=2.5cm]{geometry}
\usepackage{etoolbox}
\usepackage{longtable}%
\AtBeginEnvironment{longtable}{%
}

\usepackage{pdflscape}
\usepackage[svgnames]{xcolor}
\usepackage{colortbl}%
\newcommand{\myrowcolour}{\rowcolor[gray]{0.925}}
\usepackage{booktabs}

\ifblackandwhite
\newcommand{\highest}[1]{\textbf{#1}}% == highest score for question
\else
\newcommand{\highest}[1]{\textcolor{Maroon}{\textbf{#1}}}%
\fi

\begin{document}
\thispagestyle{empty}
\parindent0pt
%

\cheading{Fake Course Evaluation Summary for \textsc{course
1234y}}{Sept.\ 2010 --- May 2011}

\begin{longtable}{@{}l rr rr rr rr rr rr}
% pairs: absolute number (percentage)

\toprule%
\centering%
& \multicolumn{2}{c}{{{\bfseries Excellent}}}
& \multicolumn{2}{c}{{{\bfseries Very Good}}}
& \multicolumn{2}{c}{{{\bfseries Good}}}
& \multicolumn{2}{c}{{{\bfseries Average}}}
& \multicolumn{2}{c}{{{\bfseries Poor}}}
& \multicolumn{2}{c}{{{\bfseries Very Poor}}} \\

\cmidrule[0.4pt](r{0.125em}){1-1}%
\cmidrule[0.4pt](lr{0.125em}){2-3}%
\cmidrule[0.4pt](lr{0.125em}){4-5}%
\cmidrule[0.4pt](lr{0.125em}){6-7}%
\cmidrule[0.4pt](lr{0.125em}){8-9}%
\cmidrule[0.4pt](lr{0.125em}){10-11}%
\cmidrule[0.4pt](l{0.25em}){12-13}%
% \midrule

Some question about the Instructor or Course & 2 & (7.14) & 4 &
(14.29) & \highest{12} & \highest{(42.86)} & 4
& (14.29) & 6 & (21.43) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & 3 & (10.71) &
\highest{15} & \highest{(53.57)} & 5 & (17.86) & 5 & (17.86) & 0 &
(0.00) & 0 & (0.00) \\

Some question about the Instructor or Course & 4 & (14.29) & 8 &
(28.57) & \highest{15}
& \highest{(53.57)} & 1 & (3.57) & 0 & (0.00) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & 3 & (10.71) & 8 &
(28.57) & \highest{10} & \highest{(35.71)}
& 5 & (17.86) & 2 & (7.14) & 0 & (0.00) \\

Some question about the Instructor or Course & 6 & (21.43) &
\highest{9} & \highest{(32.14)}
& 4 & (14.29) & \highest{9} & \highest{(32.14)} & 0 & (0.00) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & \highest{10} &
\highest{(35.71)} & \highest{10} & \highest{(35.71)}
& 3 & (10.71) & 5 & (17.86) & 0 & (0.00) & 0 & (0.00) \\

Some question about the Instructor or Course & \highest{12} &
\highest{(42.86)} & \highest{12} & \highest{(42.86)} & 3
& (10.71) & 1 & (3.57) & 0 & (0.00) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & \highest{12} &
\highest{(42.86)} & 3 & (10.71) & 7
& (25.00) & 5 & (17.86) & 1 & (3.57) & 0 & (0.00) \\

Some question about the Instructor or Course & \highest{10} &
\highest{(35.71)} & 6 & (21.43) & 6 & (21.43) & 6 & (21.43)
& 1 & (3.57) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & 5 & (17.86) & 5 &
(17.86) & \highest{12} & \highest{(42.86)} & 2 & (7.14)
& 3 & (10.71) & 1 & (3.57)\\

Some question about the Instructor or Course & 3 & (10.71) & 8 &
(28.57) & \highest{11} & \highest{(39.29)} & 3 & (10.71) & 3 & (10.71)
& 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & \highest{18} &
\highest{(64.29)}
& 5 & (17.86) & 3 & (10.71) & 1 & (3.57) & 1 & (3.57) & 0 & (0.00) \\

Some question about the Instructor or Course & \highest{15} &
\highest{(53.57)}
& 7 & (25.00) & 2 & (7.14) & 2 & (7.14) & 2 & (7.14) & 0 & (0.00) \\

\myrowcolour%
Some question about the Instructor or Course & 3 & (10.71) &
\highest{13} & \highest{(46.43)} & 4 & (14.29) & 6 & (21.43) & 2
& (7.14) & 0 & (0.00) \\

\bottomrule

\end{longtable}

\end{document}


I read that I can incorporate the first part before the begin document into the LyX file by using the Documents-->Settings-->LaTeX preamble. The I created a latex input in LyX (Ctrl + L) and entered the rest of the code (the table). However, when I try to compile everything in LyX it doesn't work. I get many error messages with fontspec error font not found when I hit file-->export-->Pdf(XeTEX). I think the fontspec package is not installed but I don't know how I can install it...can somebody tell me how I could include this table into my LyX file..?

• Welcome to TeX.SX! The use of fontspec requires compiling with XeLaTeX or LuaLaTex, does it work if you compile with either of those? – Torbjørn T. Apr 19 '14 at 20:17
• I tried to export (PDF with XeLaTeX) in Lyx but I still get the error..for the coudnt find font error the complete message is then ]{LinLibertineO} % |''''''''''''''''''''''''''''''''''''''''''''''' | A font might not be found for many reasons. | Check the spelling, where the font is installed etc. etc. – user3069326 Apr 20 '14 at 7:00
• Forgive me, I obviously can't read, as I didn't notice that you used XeTeX already, so my previous comment was a bit pointless. You could try removing \usepackage{fontspec}% \defaultfontfeatures{Ligatures=TeX}% \setmainfont[% Numbers = OldStyle , ItalicFont = LinLibertineOI , BoldItalicFont = LinLibertineOBI , BoldFont = LinLibertineOB , ]{LinLibertineO}% and adding \usepackage{libertine} instead. – Torbjørn T. Apr 20 '14 at 7:26
• okay i tried this but got an error saying File libertine.sty not found – user3069326 Apr 20 '14 at 7:59
• Ok. Does it work if you remove \usepackage{libertine}? These lines only change the font, is it important to use that specific font? As for the missing package, what TeX distribution (MikTeX, TeX Live) are you using? – Torbjørn T. Apr 20 '14 at 8:20

(This is sort of a summary and extension of comments.)

### Installing

First, I'll note that the code you posted compiles without error on my system (recently updated TeX Live 2013 on Kubuntu) with either LuaTeX or XeTeX. If your system cannot find the fonts, then either they are not part of the TeX Live version that is in the Ubuntu repositories, or you haven't installed the package containing them. (I do not know which package this is.)

Usually it is recommended to install TeX Live via the installer from TUG.org (How to install "vanilla" TeXLive on Debian or Ubuntu?), as the Ubuntu version of TeX Live is, or at least has been, somewhat outdated. The TUG version has the added benefit of the tlmgr tool, which lets you update packages as new versions appear on CTAN and in TL.

If this is not an option, and the libertine package, which provides these fonts, is not available in the Ubuntu repos, you can install the package manually. I haven't tried this myself, but I think you can download the libertine.tds.zip file from http://www.ctan.org/pkg/libertine, and unzip this in ~/texmf/. (See e.g. http://www.dickimaw-books.com/latex/novices/html/installsty.html and How to install LaTeX .zip package (from CTAN) using texhash on a 'nix system? -- I couldn't find better resources right now.)

Another option is to get just the OpenType font files (e.g. http://www.ctan.org/tex-archive/fonts/libertine/opentype) and install these to your system, as with any other font you download. I think you can simply open them in the Font Manager (or whatever it is called) and click install.

### Not using that font

If using that particular font is not necessary, you can try removing

\setmainfont[%
Numbers        = OldStyle ,
ItalicFont     = LinLibertineOI ,
BoldItalicFont = LinLibertineOBI ,
BoldFont       = LinLibertineOB ,
]{LinLibertineO}%


from the preamble. Then you will get the standard Latin Modern font instead. The code may then work without installing anything.

You need to keep the fontspec package because of the lines saying

\AtBeginEnvironment{longtable}{%
}


as \addfontfeature is defined by fontspec. I don't know exactly what that does though, and judging by the comment you need to compile with LuaTeX, not XeTeX, for it to have any effect.

### Using pdflatex (should you for some reason want to)

If you in addition remove the fontspec package, the \defaultfontfeatures and the \AtBeginEnvironment{longtable}{... then you can compile with PDFLaTeX instead likely without making any changes to your system. The preamble will then look like

\newif\ifblackandwhite
% \blackandwhitetrue

\usepackage[hmargin=2cm,vmargin=2.5cm]{geometry}
\usepackage{longtable}%

\usepackage{pdflscape}
\usepackage[svgnames]{xcolor}
\usepackage{colortbl}
\newcommand{\myrowcolour}{\rowcolor[gray]{0.925}}
\usepackage{booktabs}

\ifblackandwhite
\newcommand{\highest}[1]{\textbf{#1}}% == highest score for question
\else
\newcommand{\highest}[1]{\textcolor{Maroon}{\textbf{#1}}}%
\fi


Finally, if you install the libertine package, then you can use this with PDFLaTeX as well, so to get the Libertine fonts, just add \usepackage{libertine} to the preamble posted just above.

### Landscape

The table as specified is too wide for a normal page, which is why the landscape is added to the document class options. Such options are in LyX added via the Custom field in Document --> Settings --> Document Class.

However, if this table is part of a larger document, you likely don't want everything landscape, so you can use the landscape environment instead. Add \begin{landscape} at the beginning of the ERT, and \end{landscape} at the end. Note that you will get a page break before the landscape page.

### Complete LyX file

The code below is a sample LyX file. You can paste it into an empty text document in a text editor (e.g. Gedit), save it as a .lyx file, and open it in LyX.

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\textclass article
\begin_preamble
\newif\ifblackandwhite
% \blackandwhitetrue

\usepackage[hmargin=2cm,vmargin=2.5cm]{geometry}
\usepackage{longtable}%

%%% START PDFTEX-BLOCK
% To be able to use PDFTeX, remove everything within this block
\usepackage{fontspec}%
\defaultfontfeatures{Ligatures=TeX}%
\setmainfont[%
Numbers        = OldStyle ,
ItalicFont     = LinLibertineOI ,
BoldItalicFont = LinLibertineOBI ,
BoldFont       = LinLibertineOB ,
]{LinLibertineO}%
\usepackage{etoolbox}
\AtBeginEnvironment{longtable}{%
}
%%% END BLOCK

\usepackage{pdflscape}
\usepackage[svgnames]{xcolor}
\usepackage{colortbl}%
\newcommand{\myrowcolour}{\rowcolor[gray]{0.925}}
\usepackage{booktabs}

\ifblackandwhite
\newcommand{\highest}[1]{\textbf{#1}}% == highest score for question
\else
\newcommand{\highest}[1]{\textcolor{Maroon}{\textbf{#1}}}%
\fi
\end_preamble
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman default
\font_sans default
\font_typewriter default
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_amsmath 1
\use_esint 1
\use_mhchem 1
\use_mathdots 1
\cite_engine basic
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\use_refstyle 1
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false

\begin_body

\begin_layout Standard
Some text on a page.
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

\backslash
begin{landscape}
\end_layout

\begin_layout Plain Layout

\backslash
thispagestyle{empty}%
\end_layout

\begin_layout Plain Layout

\backslash
parindent0pt%
\end_layout

\begin_layout Plain Layout

\backslash
\backslash
textsc{course     1234y}}{Sept.
\backslash
2010 --- May 2011}%
\end_layout

\begin_layout Plain Layout

\backslash
begin{longtable}{@{}l rr rr rr rr rr rr}
\end_layout

\begin_layout Plain Layout

\backslash
toprule
\end_layout

\begin_layout Plain Layout

\backslash
centering
\end_layout

\begin_layout Plain Layout

&
\backslash
multicolumn{2}{c}{{{
\backslash
bfseries Excellent}}}
\end_layout

\begin_layout Plain Layout

&
\backslash
multicolumn{2}{c}{{{
\backslash
bfseries Very Good}}}
\end_layout

\begin_layout Plain Layout

&
\backslash
multicolumn{2}{c}{{{
\backslash
bfseries Good}}}
\end_layout

\begin_layout Plain Layout

&
\backslash
multicolumn{2}{c}{{{
\backslash
bfseries Average}}}
\end_layout

\begin_layout Plain Layout

&
\backslash
multicolumn{2}{c}{{{
\backslash
bfseries Poor}}}
\end_layout

\begin_layout Plain Layout

&
\backslash
multicolumn{2}{c}{{{
\backslash
bfseries Very Poor}}}
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\end_layout

\begin_layout Plain Layout

\backslash
cmidrule[0.4pt](r{0.125em}){1-1}
\end_layout

\begin_layout Plain Layout

\backslash
cmidrule[0.4pt](lr{0.125em}){2-3}
\end_layout

\begin_layout Plain Layout

\backslash
cmidrule[0.4pt](lr{0.125em}){4-5}
\end_layout

\begin_layout Plain Layout

\backslash
cmidrule[0.4pt](lr{0.125em}){6-7}
\end_layout

\begin_layout Plain Layout

\backslash
cmidrule[0.4pt](lr{0.125em}){8-9}
\end_layout

\begin_layout Plain Layout

\backslash
cmidrule[0.4pt](lr{0.125em}){10-11}
\end_layout

\begin_layout Plain Layout

\backslash
cmidrule[0.4pt](l{0.25em}){12-13}
\end_layout

\begin_layout Plain Layout

\backslash
\end_layout

\begin_layout Plain Layout

\end_layout

\begin_layout Plain Layout

Some question about the Instructor or Course & 2 & (7.14) & 4 & (14.29) &

\backslash
highest{12} &
\backslash
highest{(42.86)} & 4 & (14.29) & 6 & (21.43) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\backslash
myrowcolour Some question about the Instructor or Course & 3 & (10.71) &

\backslash
highest{15} &
\backslash
highest{(53.57)} & 5 & (17.86) & 5 & (17.86) & 0 & (0.00) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

Some question about the Instructor or Course & 4 & (14.29) & 8 & (28.57) &

\backslash
highest{15} &
\backslash
highest{(53.57)} & 1 & (3.57) & 0 & (0.00) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\backslash
myrowcolour Some question about the Instructor or Course & 3 & (10.71) &
8 & (28.57) &
\backslash
highest{10} &
\backslash
highest{(35.71)} & 5 & (17.86) & 2 & (7.14) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

Some question about the Instructor or Course & 6 & (21.43) &
\backslash
highest{9} &
\backslash
highest{(32.14)} & 4 & (14.29) &
\backslash
highest{9} &
\backslash
highest{(32.14)} & 0 & (0.00) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\backslash
myrowcolour Some question about the Instructor or Course &
\backslash
highest{10} &
\backslash
highest{(35.71)} &
\backslash
highest{10} &
\backslash
highest{(35.71)} & 3 & (10.71) & 5 & (17.86) & 0 & (0.00) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

Some question about the Instructor or Course &
\backslash
highest{12} &
\backslash
highest{(42.86)} &
\backslash
highest{12} &
\backslash
highest{(42.86)} & 3 & (10.71) & 1 & (3.57) & 0 & (0.00) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\backslash
myrowcolour Some question about the Instructor or Course &
\backslash
highest{12} &
\backslash
highest{(42.86)} & 3 & (10.71) & 7 & (25.00) & 5 & (17.86) & 1 & (3.57) & 0 &
(0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

Some question about the Instructor or Course &
\backslash
highest{10} &
\backslash
highest{(35.71)} & 6 & (21.43) & 6 & (21.43) & 6 & (21.43) & 1 & (3.57) & 0 &
(0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\backslash
myrowcolour Some question about the Instructor or Course & 5 & (17.86) &
5 & (17.86) &
\backslash
highest{12} &
\backslash
highest{(42.86)} & 2 & (7.14) & 3 & (10.71) & 1 & (3.57)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

Some question about the Instructor or Course & 3 & (10.71) & 8 & (28.57) &

\backslash
highest{11} &
\backslash
highest{(39.29)} & 3 & (10.71) & 3 & (10.71) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\backslash
myrowcolour Some question about the Instructor or Course &
\backslash
highest{18} &
\backslash
highest{(64.29)} & 5 & (17.86) & 3 & (10.71) & 1 & (3.57) & 1 & (3.57) & 0 &
(0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

Some question about the Instructor or Course &
\backslash
highest{15} &
\backslash
highest{(53.57)} & 7 & (25.00) & 2 & (7.14) & 2 & (7.14) & 2 & (7.14) & 0 & (0.00)

\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\backslash
myrowcolour Some question about the Instructor or Course & 3 & (10.71) &

\backslash
highest{13} &
\backslash
highest{(46.43)} & 4 & (14.29) & 6 & (21.43) & 2 & (7.14) & 0 & (0.00)
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

\backslash
bottomrule
\end_layout

\begin_layout Plain Layout

\backslash
end{longtable}
\end_layout

\begin_layout Plain Layout

\backslash
end{landscape}
\end_layout

\end_inset

\end_layout

\begin_layout Standard
Sone more text on the next page.
\end_layout

\end_body
\end_document