Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
There are floating tables and inline tables:
Sometimes you need to position a table in a document in a certain way. To do this, you need to use the alignment tools and set the indents between the table and the surrounding text.
In this article, we will discuss what options Aspose.Words provides for positioning.
You can set the position of an inline table using the Aspose.Words API and the Alignment property. Thus, you can adjust the alignment of the table relative to the document page.
The following code example shows how to set the position of an inline table:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C.git. | |
auto doc = MakeObject<Document>(MyDir + u"Tables.docx"); | |
auto table = System::ExplicitCast<Table>(doc->GetChild(NodeType::Table, 0, true)); | |
// Align the table to the center of the page. | |
table->set_Alignment(TableAlignment::Center); |
If the table text wrapping is set to Around, you can get the table’s horizontal and vertical alignment using the RelativeHorizontalAlignment and RelativeVerticalAlignment properties.
With other types of text wrapping, you can get inline table alignment using the Alignment property.
The following code example shows how to get the table’s alignment:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C.git. | |
auto doc = MakeObject<Document>(MyDir + u"Tables.docx"); | |
auto table = System::ExplicitCast<Table>(doc->GetChild(NodeType::Table, 0, true)); | |
if (table->get_TextWrapping() == TextWrapping::Around) | |
{ | |
std::cout << System::EnumGetName(table->get_RelativeHorizontalAlignment()) << std::endl; | |
std::cout << System::EnumGetName(table->get_RelativeVerticalAlignment()) << std::endl; | |
} | |
else | |
{ | |
std::cout << System::EnumGetName(table->get_Alignment()) << std::endl; | |
} |
The position of a floating table is determined using the following properties:
The following code example shows how to get the position of a floating table:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C.git. | |
auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx"); | |
for (const auto& table : System::IterateOver<Table>(doc->get_FirstSection()->get_Body()->get_Tables())) | |
{ | |
// If the table is floating type, then print its positioning properties. | |
if (table->get_TextWrapping() == TextWrapping::Around) | |
{ | |
std::cout << System::EnumGetName(table->get_HorizontalAnchor()) << std::endl; | |
std::cout << System::EnumGetName(table->get_VerticalAnchor()) << std::endl; | |
std::cout << table->get_AbsoluteHorizontalDistance() << std::endl; | |
std::cout << table->get_AbsoluteVerticalDistance() << std::endl; | |
std::cout << System::Convert::ToString(table->get_AllowOverlap()) << std::endl; | |
std::cout << table->get_AbsoluteHorizontalDistance() << std::endl; | |
std::cout << System::EnumGetName(table->get_RelativeVerticalAlignment()) << std::endl; | |
std::cout << ".............................." << std::endl; | |
} | |
} |
Just like getting, you can set the position of a floating table using the same Aspose.Words API.
It is important to know that alignment and horizontal and vertical distance are combined properties and one can reset the other. For example, setting the RelativeHorizontalAlignment will reset the AbsoluteHorizontalDistance to its default value and vice versa. The same is true for the vertical arrangement.
The following code example shows how to set the position of a floating table:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C.git. | |
auto doc = MakeObject<Document>(MyDir + u"Table wrapped by text.docx"); | |
SharedPtr<Table> table = doc->get_FirstSection()->get_Body()->get_Tables()->idx_get(0); | |
table->set_AbsoluteHorizontalDistance(10); | |
table->set_RelativeVerticalAlignment(VerticalAlignment::Center); | |
doc->Save(ArtifactsDir + u"WorkingWithTables.FloatingTablePosition.docx"); |
Aspose.Words also provides an opportunity to find out the distances between tables and surrounding texts:
The following code example shows how to get the distance between a table and its surrounding text:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C.git. | |
auto doc = MakeObject<Document>(MyDir + u"Tables.docx"); | |
std::cout << "\nGet distance between table left, right, bottom, top and the surrounding text." << std::endl; | |
auto table = System::ExplicitCast<Table>(doc->GetChild(NodeType::Table, 0, true)); | |
std::cout << table->get_DistanceTop() << std::endl; | |
std::cout << table->get_DistanceBottom() << std::endl; | |
std::cout << table->get_DistanceRight() << std::endl; | |
std::cout << table->get_DistanceLeft() << std::endl; |
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.