如何创建没有缩进的列表?(How to create a list without indentation?)

系统教程 行业动态 更新时间:2024-06-14 16:59:17
如何创建没有缩进的列表?(How to create a list without indentation?)

是否可以创建没有缩进的编号列表? 有些像这样的:

1 A

1-1 A_A

2 B

2-1 B_B

2-1-1 B_B_B

Is it possible to create numbered list without indent ? Somethig like that :

1 A

1-1 A_A

2 B

2-1 B_B

2-1-1 B_B_B

最满意答案

请查看ListNumbers示例。

当我们创建一个像这样的有序列表时:

List list1 = new List(List.ORDERED); list1.setFirst(8); for (int i = 0; i < 5; i++) { list1.add("item"); } document.add(list1);

我们得到如下结果:

在这里输入图像描述

必要时,在标签和列表项的内容之间添加额外的空间。

您的问题是:我们如何删除此缩进。 这是添加一行到您的代码的问题:

List list2 = new List(List.ORDERED); list2.setFirst(8); list2.setAlignindent(false); for (int i = 0; i < 5; i++) { list2.add("item"); } document.add(list2);

现在结果如下:

在这里输入图像描述

正如你所看到的,在项目8和9之后没有额外的空间。

这个答案很简单,我无法相信这实际上是整个问题(如果是的话,这意味着你自己没有做任何努力)。 看看期望的结果,我认为你在帖子主题中提到了更多内容。

我懂了:

自定义编号:不. 之后的数字。 嵌套结构:2,然后是2_1,依此类推。

在有序列表的情况下更改列表符号可以使用setPreSymbol()和setPostSymbol()方法完成。

看看这个片段:

List list3 = new List(List.ORDERED); list3.setFirst(8); list3.setAlignindent(false); list3.setPostSymbol(" "); for (int i = 0; i < 5; i++) { list3.add("item"); List list = new List(List.ORDERED); list.setPreSymbol(String.valueOf(8 + i) + "_"); list.setPostSymbol(" "); list.add("item 1"); list.add("item 2"); list3.add(list); } document.add(list3);

首先我们删除每个数字后面自动添加的点,我们使用getPostSymbol()方法:

list3.setPostSymbol(" ");

然后我们在list3嵌套list 。 由于我们想要获得类似于8_1等的结果,我们使用setPreSymbol()方法,如下所示:

list.setPreSymbol(String.valueOf(8 + i) + "_");

现在结果如下:

在这里输入图像描述

显然,有人可能会说:为什么你想使用List来获得这种结果呢? 为什么不只是一系列的Paragraph对象。 但是:如果您正在创建标记PDF,最好使用List因为iText会自动将该内容标记为列表(例如,在可访问性的上下文中)。

Please take a look at the ListNumbers examples.

When we create an ordered list like this:

List list1 = new List(List.ORDERED); list1.setFirst(8); for (int i = 0; i < 5; i++) { list1.add("item"); } document.add(list1);

We get a result like this:

enter image description here

Where necessary, extra space is added between the label and the content of a list item.

Your question is: how can we remove this indentation. That's a matter of adding a single line to your code:

List list2 = new List(List.ORDERED); list2.setFirst(8); list2.setAlignindent(false); for (int i = 0; i < 5; i++) { list2.add("item"); } document.add(list2);

Now the result looks like this:

enter image description here

As you can see, no extra space was added after items 8 and 9.

This answer is so simple that I can't believe that this was actually the whole question (if it was, that would mean that you didn't do any effort whatsoever yourself). Looking at the desired result, I assume that there is more at play then what you mention in the subject of your post.

I see:

Custom numbering: no . after the number. A nested structure: 2, followed by 2_1, and so on.

Changing the list symbol in case of ordered lists can be done using the setPreSymbol() and setPostSymbol() methods.

Take a look at this snippet:

List list3 = new List(List.ORDERED); list3.setFirst(8); list3.setAlignindent(false); list3.setPostSymbol(" "); for (int i = 0; i < 5; i++) { list3.add("item"); List list = new List(List.ORDERED); list.setPreSymbol(String.valueOf(8 + i) + "_"); list.setPostSymbol(" "); list.add("item 1"); list.add("item 2"); list3.add(list); } document.add(list3);

First we remove the dot that is added after each number automatically, we use the getPostSymbol() method for this:

list3.setPostSymbol(" ");

Then we nest list inside list3. As we want to get a result that looks like 8_1, 8_2, 9_1, etc., we use the setPreSymbol() method like this:

list.setPreSymbol(String.valueOf(8 + i) + "_");

Now the result looks like this:

enter image description here

Obviously, one could argue: why do you want to use a List for this kind of result? Why not just a series of Paragraph objects. However: if you're creating Tagged PDF, it's better to use List because iText will then automatically tag that content as a list (e.g. in the context of accessibility).

更多推荐

本文发布于:2023-04-16 14:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/bcb8d7e94dad280dd6e54301c74332b9.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:列表   create   indentation   list

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!