我正在写一些项目参考,我想创建以下布局:
现在我已经尝试过并得到了以下布局:
目前,我创建了一个表格来保留列,但我需要一种方法来将左列上的文本调整到更靠近左侧的位置,这样文本就不会刚好从左列的中间开始。我该怎么做?
我的代码:
% !TeX program = lualatex
\documentclass[a4paper,12pt]{article}
%font encoding
\usepackage[onehalfspacing]{setspace}
\usepackage{fontspec}
\setmainfont{Arial}
\usepackage[document]{ragged2e}
\usepackage[textwidth=160mm, textheight=240mm]{geometry}
%language
\usepackage[ngerman]{babel}
\usepackage{lipsum}
%table format
\usepackage{tabularx}
\usepackage{float}
%Styles
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{atbegshi}
\usepackage{fancyhdr}
\usepackage{xcolor}
\usepackage{lipsum}
\pagenumbering{gobble}
\definecolor{bluey}{RGB}{12,3,150}
\newcommand\Sitebar{%
\begin{tikzpicture}[remember picture,overlay]
\fill[lightgray]
(current page.north west) -- ([xshift = 4cm]current page.north west) --
([xshift=7cm]current page.north west) --
([xshift=7cm]current page.south west) --
([xshift=0cm]current page.south west) -- cycle;
\draw [gray, line width = 1.5pt] ([xshift=7cm]current page.north west) --
([xshift=7cm]current page.south west);
\end{tikzpicture}%
}
%header format
\newcommand\HeaderTwo{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
(current page.north west) -- (current page.north east) --
([yshift=0.5cm]current page.north east|-current page text area.north east) --
([yshift=1.5cm]current page.north west|-current page text area.north west) -- cycle;
\end{tikzpicture}%
}
% left separator
\newcommand\sepLeft{%
\vspace{0.5cm}
\begin{tikzpicture}[remember picture,overlay]
\vspace{1cm}
\draw [black, line width = 2pt] (-1.75,0.5) -- (3.8,0.5);
\draw [bluey, line width = 2pt] (5.2,0.5) -- (17.5,0.5);
\end{tikzpicture}%
}
\begin{document}
\Sitebar
\HeaderTwo
\hspace{5cm} \textbf{\Huge \color{gray} Projektreferenzen}\\
%separator
\sepLeft
\begin{table}[H]
\begin{tabularx}{\linewidth}{ p{4cm} p{0.2cm} p{10cm}}
Very Very long text to see how big this tabular actually is && \lipsum[1]
\end{tabularx}
\end{table}
\end{document}
答案1
使用时tabularx
至少有一列必须是 类型X
。
\begin{tabularx}\linewidth{p{4cm}p{.2cm}p{10cm}}
指示tabularx
调整X
类型列,以使总表格宽度为\linewidth
,但不提供任何X
类型列供其调整。也就是说,它同时告诉 LaTeX 表格应该是确切地14.2厘米加上相关的柱间间距。
我认为第一列或最后一列应该是X
。在下面的代码中,我以这种方式设置最后一列。我还调整了一些东西以获得适合大小的适当行距,并删除了一些示例\Huge
中不需要或根本不起作用的东西(例如)。\vspace
tikzpicture
我改变字体只是因为我没有 Arial。
\documentclass[a4paper,12pt,ngerman]{article}
%font encoding
\usepackage[onehalfspacing]{setspace}
\usepackage{fontspec}
\setmainfont{Noto Sans}% I don't have Arial
\usepackage[document]{ragged2e}
\usepackage[textwidth=160mm, textheight=240mm]{geometry}
%language
\usepackage{babel}
\usepackage{lipsum}
%table format
\usepackage{tabularx}
\usepackage{float}
%Styles
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\pagenumbering{gobble}% this is a really bad idea
\definecolor{bluey}{RGB}{12,3,150}
\newcommand\Sitebar{%
\begin{tikzpicture}[remember picture,overlay]
\fill[lightgray]
(current page.north west) -- ([xshift = 4cm]current page.north west) --
([xshift=7cm]current page.north west) --
([xshift=7cm]current page.south west) --
(current page.south west) -- cycle;
\draw [gray, line width = 1.5pt] ([xshift=7cm]current page.north west) --
([xshift=7cm]current page.south west);
\end{tikzpicture}%
}
%header format
\newcommand\HeaderTwo{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
(current page.north west) -- (current page.north east) --
([yshift=0.5cm]current page.north east|-current page text area.north east) --
([yshift=1.5cm]current page.north west|-current page text area.north west) -- cycle;
\end{tikzpicture}%
}
% left separator
\newcommand\sepLeft{%
\vspace*{0.5cm}%
\begin{tikzpicture}[remember picture,overlay]
\draw [black, line width = 2pt] (-1.75,0.5) -- (3.8,0.5);
\draw [bluey, line width = 2pt] (5.2,0.5) -- (17.5,0.5);
\end{tikzpicture}%
}
\begin{document}
\Sitebar
\HeaderTwo
\hspace{5cm} {\bfseries\Huge\color{gray} Projektreferenzen\par}
\sepLeft % separator
\begin{table}[H]
\begin{tabularx}{\linewidth}{ p{4cm} p{0.2cm} X}
Very Very long text to see how big this tabular actually is && \lipsum[1]
\end{tabularx}
\end{table}
\end{document}
\pagenumbering{gobble}
我认为这是一个非常糟糕的想法。你确定你不想不加页码吗?显示? 为此,您可以使用\pagestyle{empty}
and/or,\thispagestyle{empty}
或者,如果确实有必要,重新定义\thepage
为\relax
或某物。
答案2
使用paracol
包可以并行编写多列,甚至可以同步列之间的段落。
以下代码显示了paracol
环境对您的示例的一种可能应用。geometry
边距已更改为减少左右边距。命令\columnratio
定义不同列之间的比例,在本例中仅定义了左列(2 列)。
% !TeX program = lualatex
\documentclass[a4paper,12pt]{article}
%font encoding
\usepackage[onehalfspacing]{setspace}
\usepackage{fontspec}
\setmainfont{Arial}
\usepackage[document]{ragged2e}
\usepackage[left=8mm, right=8mm, textheight=240mm]{geometry}
\usepackage{paracol}
%language
\usepackage[ngerman]{babel}
\usepackage{lipsum}
%table format
\usepackage{tabularx}
\usepackage{float}
%Styles
%\usepackage{tikz} % <- already loaded by `tikzpagenodes`
\usepackage{tikzpagenodes}
\usepackage{atbegshi}
\usepackage{fancyhdr}
%\usepackage{xcolor} %<- already loaded by `tikz`
%\usepackage{lipsum} %<- duplicated
\pagenumbering{gobble}
\definecolor{bluey}{RGB}{12,3,150}
\newcommand\Sitebar{%
\begin{tikzpicture}[remember picture,overlay]
\fill[lightgray]
(current page.north west) -- ([xshift = 4cm]current page.north west) --
([xshift=7cm]current page.north west) --
([xshift=7cm]current page.south west) --
([xshift=0cm]current page.south west) -- cycle;
\draw [gray, line width = 1.5pt] ([xshift=7cm]current page.north west) --
([xshift=7cm]current page.south west);
\end{tikzpicture}%
}
%header format
\newcommand\HeaderTwo{%
\begin{tikzpicture}[remember picture,overlay]
\fill[bluey]
(current page.north west) -- (current page.north east) --
([yshift=0.5cm]current page.north east|-current page text area.north east) --
([yshift=1.5cm]current page.north west|-current page text area.north west) -- cycle;
\end{tikzpicture}%
}
% left separator
\newcommand\sepLeft{%
\vspace{0.5cm}
\begin{tikzpicture}[remember picture,overlay]
\hspace{1.5cm}
\draw [black, line width = 2pt] (-1.75,0.5) -- (3.8,0.5);
\draw [bluey, line width = 2pt] (5.2,0.5) -- (17.5,0.5);
\end{tikzpicture}%
}
\setlength{\columnsep}{12mm}
\columnratio{.3}
\begin{document}
\Sitebar
\HeaderTwo
\begin{paracol}{2}
\begin{rightcolumn}
\bfseries\Huge\color{gray}Projektreferenzen\par
\end{rightcolumn}
\end{paracol}
\sepLeft
\begin{paracol}{2}
\lipsum[2]
\switchcolumn
\lipsum[1]
\end{paracol}
\end{document}