在 Lyx 中为表格编写 Latex 代码

在 Lyx 中为表格编写 Latex 代码

我在 TeX.SX 上找到了这个表格模板:

漂亮的表格样本

我想复制的表格是

   \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}{%
  \addfontfeature{RawFeature=+tnum;-onum}%  <--- requires LuaTeX
}

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

\ifblackandwhite
  \newcommand{\cheading}[2]{\textbf{#1\hfill #2}}
  \newcommand{\highest}[1]{\textbf{#1}}% == highest score for question
\else
  \newcommand{\cheading}[2]{\textcolor{Maroon}{\textbf{#1\hfill #2}}}
  \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
\endhead


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}

我读到,我可以使用 Documents-->Settings-->LaTeX 前言将开始文档之前的第一部分合并到 LyX 文件中。我在 LyX 中创建了一个 latex 输入(Ctrl + L)并输入了其余代码(表格)。但是,当我尝试在 LyX 中编译所有内容时,它不起作用。fontspec当我点击 file-->export-->Pdf(XeTEX) 时,我收到许多错误消息,提示找不到错误字体。我认为该fontspec软件包未安装,但我不知道如何安装它...有人可以告诉我如何将此表格包含到我的 LyX 文件中吗?

答案1

(这算是评论的总结和延伸。)

安装

首先,我要指出的是,您发布的代码在我的系统(最近在 Kubuntu 上更新了 TeX Live 2013)上使用 LuaTeX 或 XeTeX 编译时没有出现错误。如果您的系统找不到字体,那么要么它们不是 Ubuntu 存储库中的 TeX Live 版本的一部分,要么您没有安装包含它们的软件包。(我不知道这是哪个软件包。)

通常建议通过 TUG.org 的安装程序安装 TeX Live(如何在 Debian 或 Ubuntu 上安装“原始” TeXLive?),因为 Ubuntu 版 TeX Live 已经或至少已经有些过时了。TUG 版具有该tlmgr工具的额外优势,它允许您在 CTAN 和 TL 中出现新版本时更新软件包。

如果这不是一个选项,并且libertine提供这些字体的软件包在 Ubuntu 存储库中不可用,您可以手动安装该软件包。我自己还没有尝试过,但我认为你可以libertine.tds.ziphttp://www.ctan.org/pkg/libertine,并将其解压缩到~/texmf/。(例如参见http://www.dickimaw-books.com/latex/novices/html/installsty.html如何在 'nix 系统上使用 texhash 安装 LaTeX .zip 包(来自 CTAN)?——我现在找不到更好的资源。)

另一个选择是只获取 OpenType 字体文件(例如http://www.ctan.org/tex-archive/fonts/libertine/opentype) 并将它们安装到您的系统中,就像您下载的任何其他字体一样。我认为您只需在字体管理器 (或任何名称) 中打开它们,然后单击安装即可。

没有使用该字体

如果不需要使用该特定字体,您可以尝试删除

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

从序言中。然后您将获得标准的拉丁现代字体。代码可以在不安装任何东西的情况下运行。

你需要保留这个fontspec包裹,因为上面写着

\AtBeginEnvironment{longtable}{%
  \addfontfeature{RawFeature=+tnum;-onum}%  <--- requires LuaTeX
}

就像\addfontfeature所定义的一样fontspec。不过我不清楚它到底起什么作用,根据注释判断,你需要使用 LuaTeX 而不是 XeTeX 进行编译,这样它才会起作用。

使用pdflatex(如果你出于某种原因想要使用)

如果你另外删除了fontspec软件包,那么\defaultfontfeatures\AtBeginEnvironment{longtable}{...就可以使用 PDFLaTeX 进行编译,而无需对系统进行任何更改。序言将如下所示

\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{\cheading}[2]{\textbf{#1\hfill #2}}
  \newcommand{\highest}[1]{\textbf{#1}}% == highest score for question
\else
  \newcommand{\cheading}[2]{\textcolor{Maroon}{\textbf{#1\hfill #2}}}
  \newcommand{\highest}[1]{\textcolor{Maroon}{\textbf{#1}}}%
\fi

最后,如果您安装了该libertine软件包,那么您也可以将其与 PDFLaTeX 一起使用,因此要获取 Libertine 字体,只需添加\usepackage{libertine}到上面发布的序言中。

景观

指定的表格对于普通页面来说太宽,这就是为什么landscape将添加到文档类选项的原因。此类选项在 LyX 中通过风俗文档 --> 设置 --> 文档类中的字段。

但是,如果此表是较大文档的一部分,您可能不希望所有内容都横向显示,因此您可以使用环境。在 ERT 的开头和结尾处landscape添加。请注意,您将在横向页面之前获得分页符。\begin{landscape}\end{landscape}

完整的 LyX 文件

以下代码是 LyX 示例文件。您可以将其粘贴到文本编辑器(例如 Gedit)中的空文本文档中,将其保存为文件.lyx,然后在 LyX 中打开。

#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\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}{%
  \addfontfeature{RawFeature=+tnum;-onum}%  <--- requires LuaTeX
}
%%% END BLOCK


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

\ifblackandwhite
  \newcommand{\cheading}[2]{\textbf{#1\hfill #2}}
  \newcommand{\highest}[1]{\textbf{#1}}% == highest score for question
\else
  \newcommand{\cheading}[2]{\textcolor{Maroon}{\textbf{#1\hfill #2}}}
  \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
\end_header

\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
cheading{Fake Course Evaluation Summary for 
\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
endhead
\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

相关内容