我正在创建控制台 GUI 的伪乳胶界面。我不想使用 GUI 的屏幕截图,因为我需要文本才能转到下一页。
我现在有的是:
\newcommand{\codein}[1]{\textcolor{codeblue}{\textbf{\texttt{In [#1]:}}}}
\newcommand{\codeout}[1]{\textcolor{codered}{\textbf{\texttt{Out[#1]:}}}}
\begin{tabular}{ l l }
\raisebox{\baselineskip}{\codein{1}}&\begin{lstlisting}[language=sage]
5+2
3
5\end{lstlisting}\\
\codeout{1}&{test}
\end{tabular}
有没有办法将我的文本始终推到表格的顶部?
\codein
编辑添加了和的定义\codeout
。语言可以是任何语言。我的明智规范是:
\definecolor{codegreen}{RGB}{45,161,129}
\definecolor{codedarkgreen}{RGB}{0,128,0}
\definecolor{codered}{RGB}{189,74,86}
\definecolor{codepurple}{RGB}{171,51,254}
\definecolor{backcolour}{RGB}{247,247,247}
\definecolor{codeblue}{RGB}{80,106,192}
\lstdefinelanguage{sage}{
morekeywords={in},
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{codedarkgreen},
stringstyle=\color{codered},
basicstyle=\ttfamily\small,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
frame=single
}
\lstset{literate=%
*{0}{{{\color{codered!20!codegreen}0}}}1
{1}{{{\color{codered!20!codegreen}1}}}1
{2}{{{\color{codered!20!codegreen}2}}}1
{3}{{{\color{codered!20!codegreen}3}}}1
{4}{{{\color{codered!20!codegreen}4}}}1
{5}{{{\color{codered!20!codegreen}5}}}1
{6}{{{\color{codered!20!codegreen}6}}}1
{7}{{{\color{codered!20!codegreen}7}}}1
{8}{{{\color{codered!20!codegreen}8}}}1
{9}{{{\color{codered!20!codegreen}9}}}1
{=}{{{\color{codered!20!codepurple}=}}}1
{/}{{{\color{codered!20!codepurple}/}}}1
{-}{{{\color{codered!20!codepurple}-}}}1
{+}{{{\color{codered!20!codepurple}+}}}1
{*}{{{\color{codered!20!codepurple}*}}}1
{^}{{{\color{codered!20!codepurple}^}}}1
}
答案1
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{adjustbox}
\definecolor{codered}{RGB}{189,74,86}
\definecolor{codeblue}{RGB}{80,106,192}
\newcommand{\codein}[1]{\textcolor{codeblue}{\textbf{\texttt{In [#1]:}}}}
\newcommand{\codeout}[1]{\textcolor{codered}{\textbf{\texttt{Out[#1]:}}}}
\begin{document}
\begin{tabular}{ l l }
\codein{1}&\begin{adjustbox}{valign=t}\begin{lstlisting}
5+2
3
5
\end{lstlisting}\end{adjustbox}\\
\codeout{1}&{test}
\end{tabular}
\end{document}
答案2
设法弄清楚了。
使用\userpackage{calc}
你就可以说出你的文本的高度\raisebox{\baselineskip-10px}
在哪里。10px
{ l l }
另请注意,如果我更改为,我只能让它适用于我的情况{ l p{3cm} }
\begin{tabular}{ l p{3cm} }
\raisebox{\baselineskip-10px}{\codein{1}}&\begin{lstlisting}[language=sage]
5+2
3
5\end{lstlisting}\\
\codeout{1}&{test}
\end{tabular}
l
我无法完全解释和之间的区别p
。