我从采访记录中得到了以下格式:
Bob: 00:00:07.000 –> 00:00:17.000 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fermentum bibendum orci quis faucibus.
Alice: 00:00:17.000 –> 00:00:30.000 Nam sodales pharetra lorem, sit amet gravida justo vehicula non. Etiam eleifend mauris arcu. Sed lacinia augue id sollicitudin consequat.
我怎样才能像这样设计它:
Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit.
00:00:07 –> 00:00:17 Morbi fermentum bibendum orci quis faucibus.
Alice: Nam sodales pharetra lorem, sit amet gravida justo vehicula non.
00:00:17 –> 00:00:30 Morbi fermentum bibendum orci quis faucibus.Etiam eleifend mauris
arcu. Sed lacinia augue id sollicitudin consequat.
PS:我尝试制作表格,但无法将时间放在名字下面并将其与右侧的文本对齐。可能是因为缺乏经验。:)
答案1
描述
变体 1{...}
对于 4 个参数,使用更像 LaTeX 的语法:\statement
在interview
环境中。
\statement{<name>}{<from>}{<to>}{<text>}
变体 2解释原始输入:\firststatementx
并\statementx
在interview
环境中。
\statementx <name>: <from> -> <to> <text>
- 请注意,变体 2 使用“不推荐”参数类型
u
的包xparse
(请参阅xparse
手动的, 1.8 “向后兼容性”)。
正如我在评论中提到的,也可以用一些正则表达式搜索和替换原始文本,或者编写一个进行转换的小脚本。
代码
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xparse}
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\hspace{0pt}\raggedright\arraybackslash}p{#1}} % left-aligned with width as parameter
\newenvironment{interview}{%
\begin{tabular}{L{45mm} L{80mm}}
}{
\end{tabular}
}
\newcommand{\statement}[4]{%
% #1 = name, #2 = time from, #3 = time to, #4 = text
\textbf{#1:}\newline
#2 $\rightarrow$ #3
& #4\\[6mm]
}
\NewDocumentCommand{\firststatementx}{ u{: } u{ –> } u{ } }{%
% #1 = name, #2 = time from, #3 = time to
\textbf{#1:}\newline
#2 $\rightarrow$ #3
&
}
\NewDocumentCommand{\statementx}{ u{: } u{ –> } u{ } }{%
% #1 = name, #2 = time from, #3 = time to
\\[6mm]
\textbf{#1:}\newline
#2 $\rightarrow$ #3
&
}
\begin{document}
\textbf{Variant 1:}
\medskip
\begin{interview}
\statement{Bob}{00:00:07.000}{00:00:17.000}{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fermentum bibendum orci quis faucibus.}
\statement{Alice}{00:00:17.000}{00:00:30.000}{Nam sodales pharetra lorem, sit amet gravida justo vehicula non. Etiam eleifend mauris arcu. Sed lacinia augue id sollicitudin consequat.}
\end{interview}
\textbf{Variant 2:}
\medskip
\begin{interview}
\firststatementx Bob: 00:00:07.000 –> 00:00:17.000 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fermentum bibendum orci quis faucibus.
\statementx Alice: 00:00:17.000 –> 00:00:30.000 Nam sodales pharetra lorem, sit amet gravida justo vehicula non. Etiam eleifend mauris arcu. Sed lacinia augue id sollicitudin consequat.
\end{interview}
\end{document}