表格中的自动换行符具有背景颜色

表格中的自动换行符具有背景颜色

我试图限制表格大小并强制跳过行。相反,文本到达了纸张的末尾,同时我希望它在其中一个单元格中具有灰色背景。我知道宏\makegapedcells\makecell删除此功能。但我该用什么来代替呢?

在此处输入图片描述

正如您所看到的,我\makegapedcells现在甚至无法使线路移动...但我确信一定有更好的方法?

\documentclass[a4paper, 11pt]{scrartcl}
\usepackage{comment} % enables the use of multi-line comments (\ifx \fi) 
\usepackage{fullpage} % changes the margin
\usepackage[swedish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{float}
\usepackage{fancyhdr}
\usepackage{enumitem}
\pagestyle{fancy} 
\usepackage{pdfpages}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{pgfkeys}
\usepackage{titlesec} 
\usepackage{fourier, erewhon}
\usepackage{geometry} 
\usepackage{array, makecell}
\usepackage{colortbl}
\usepackage{geometry}

\setlength{\footskip}{0.1pt}
\setlength{\headheight}{80pt}
\setlength{\topmargin}{0pt}
\setlength\parindent{0pt}

\author{Peter Molander}
\usepackage{makecell}
\usepackage{multirow}

\setcellgapes{1pt}%parameter for the spacing


%%%%%%%%%%%%% Add style 2 if u want diffrent headings %%%%%%%%%%%%%%%%%
\fancypagestyle{style1}{
\lhead{\includegraphics[width=7cm]{ntk_logga.jpg}}
\rhead{Föredragningslista\\
Bilaga \textit{fumF{\yearnr}-{\FUM}.7}\\
\today\\}
\renewcommand{\headrulewidth}{0pt}
\cfoot{
\makebox{}\\
\makebox{}\\
\makebox[0.1\linewidth]{\rule{0.1\linewidth}{0.1pt}} \hspace{1cm} \makebox[0.1\linewidth]{\rule{0.1\linewidth}{0.1pt}} \hspace{1cm} \makebox[0.1\linewidth]{\rule{0.1\linewidth}{0.1pt}} \hspace{1cm} \makebox[0.1\linewidth]{\rule{0.1\linewidth}{0.1pt}} \hspace{1cm}\\}
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%% Change font size on section and sub section %%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%% And change the background color  %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setkomafont{section}{\mysection}
\newcommand{\mysection}[1]{%
    \medium\sf\bf%
    \setlength{\fboxsep}{0cm}%already boxed
    \colorbox{black!80}{%
        \begin{minipage}{\linewidth}%
            \vspace*{2pt}%Space before
            #1
            \vspace*{2pt}%Space after
        \end{minipage}%
    }}

\titleformat{\subsection}[runin]
  {\normalfont\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}[runin]
  {\normalfont\normalsize\bfseries}{\thesubsubsection}{1em}{}
\titlespacing*{\subsection}{0pt}{0.5em}{1em}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%   Insert the FUM nr your on 1-8 + Year %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\FUM{1} 
\newcommand\yearnr{19}

\newcommand{\setvalue}[1]{\pgfkeys{/variables/#1}}
\newcommand{\getvalue}[1]{\pgfkeysvalueof{/variables/#1}}
\newcommand{\declare}[1]{%
 \pgfkeys{
  /variables/#1.is family,
  /variables/#1.unknown/.style = {\pgfkeyscurrentpath/\pgfkeyscurrentname/.initial = ##1}
 }%
}

\declare{}

\begin{document}
\pagestyle{style1}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%      Pre-info        %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\textbf{\Large Fullmäktigesammanträde {\FUM}}\\\\
\textbf{Datum:} 20{\yearnr}-xx-xx\\
\textbf{Tid:} 17:15\\
\textbf{Plats:} Origo\\

%\textbf{Bilagor:}\\ Bilaga 1 - Dagordning\\ %Skall alltid bifogas som bilaga
%Bilaga 2 - Motioner, revisionberättelser etc\\ %Se stadgarna för aktuella bilagor





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%      Formalia        %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Set Varible1 to the wanted sections start letter %%%%%%
 \setvalue{VARIABLE1 = F}

\noindent\textsc{\section*{\begin{tabular}{c|c}
    \color{white}{\getvalue{VARIABLE1}{\yearnr}-{\FUM}} 
    & \color{white}{Formalia} 
    %& \color{white}{Anmärkningar}
\end{tabular}}}

%%%% .1 %%%%
 \makegapedcells
\subsection*{\small \getvalue{VARIABLE1}{\yearnr}-{\FUM}.1}
    \begin{tabular}[t]{l|p{15mm}} 
        \small Mötets Öppnande 
        &  \colorbox{black!30}{\scriptsize long longlonglonglonglonglong}
    \end{tabular}
%%%% .2 %%%%
\makegapedcells
\subsection*{\small \getvalue{VARIABLE1}{\yearnr}-{\FUM}.2} 
    \begin{tabular}[t]{l|p{15mm}}  
        \small Avstängning av mobiltelefoner 
        &  longlonglonglonglonglonglongllonglonglonglonglong
    \end{tabular}



    \end{document}

答案1

我猜问题出在 p 列太窄和单词太长。p 列只有 15 毫米,所以它不能容纳长单词。另外,如果不使用一些小技巧,LaTeX 不会在单元格中的第一个单词上连字符。此外,这个longlong单词是人为的,不包含 LaTeX 可以连字符的地方(它不是瑞典语单词)。在单词中放置一些策略性\-或空格,然后查看结果。

%%%% .1 %%%%
 \makegapedcells
\subsection*{\small \getvalue{VARIABLE1}{\yearnr}-{\FUM}.1}
    \begin{tabular}[t]{l|p{25mm}} % If you are allowed
        \small Mötets Öppnande 
        &  \cellcolor{lightgray} \scriptsize \hspace{0pt}short text only
    \end{tabular}
%%%% .2 %%%%
\makegapedcells
\subsection*{\small \getvalue{VARIABLE1}{\yearnr}-{\FUM}.2} 
    \begin{tabular}[t]{l|p{25mm}}  
        \small Avstängning av mobiltelefoner 
        &  \cellcolor{lightgray} \scriptsize \hspace{0pt}only short text allowed
    \end{tabular}

它显然不适合存储长文本。尝试在普通文本中留出空格,以便 LaTeX 能够将其连字符化。如果允许,请将宽度增加到例如 25 毫米。此外,第一个单词以 开头,这样\hspace{0pt}第一个单词就会被连字符化。

我没有测试过这段代码,因为你的代码没有编译(我收到大约 100 条错误消息)。

相关内容